Concatenating the value of a select box row

Concatenating the value of a select box row

Rod.J.MillerRod.J.Miller Posts: 8Questions: 2Answers: 0
edited June 2020 in DataTables 1.9

I'm trying to concatenate 2 values firstName and lastName as select box values to use in the inline editor.

The following code gives me the firstName and lastName as the label value but the line for the value is only giving me the firstName as the value.

Field::inst( 'transferdata.transferToCarer' )
->options( Options::inst()
->table( 'accounts' )
->value( 'firstName', 'lastName' )
->label( array('firstName', 'lastName'))
)
->validator( Validate::dbValues() ),

Can anyone help?

Thanks
Rod

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,488Questions: 1Answers: 10,467 Site admin

    Hi Rod,

    Yes, the Options class will only allow a single field to be given as the value, since otherwise when it is submitted the value written would be that combined value. That might actually be what you want here looking at the code, but it isn’t a common thing to do, which is why it isn’t in the library.

    Normally what you would do is store a reference in transferToCarer to the row in the accounts table - i.e. the primary key value for Amber Lilly, or any other career selected. That would allow referential integrity - e.g. if Amber’s name had a typo in it then updating the host record would have that reflected in any use of transferToCarer (apologies if preaching to the converted here, and there is some other good reason to do this).

    If it must be done this way, then you’d need to use a custom function to get the labels and values array.

    Allan

  • Rod.J.MillerRod.J.Miller Posts: 8Questions: 2Answers: 0

    Thanks for the answer Allan. I'd love to do that but my hands are really tied by the people that have final sya in this system and they don't want to have anything like that, I have tried many times to try to get them to do that.

  • allanallan Posts: 63,488Questions: 1Answers: 10,467 Site admin
    Answer ✓

    Their call I guess.. :). Did you have any luck with the custom function?

    Allan

  • Rod.J.MillerRod.J.Miller Posts: 8Questions: 2Answers: 0

    Yes I finally got it to work. Have another issue with it not loading properly now.

This discussion has been closed.