Labels for Select Box

Labels for Select Box

TwiggitTwiggit Posts: 11Questions: 4Answers: 0
edited October 2016 in Free community support

Hi There,

I apologize if this is a silly question but I cant seem to find an example of how to do this. My database table uses numbers to represent "levels" that I normally display id a pull down menu with corresponding labels such a 1 for new, 2 for certified ect and I want to present the end user the label but submit the value to the DB. A simple thing in html but generator does not give an option for a label. It just gives:

fields: [
{
"label": "level_id:",
"name": "level_id",
"type": "select",
"options": [
"1",
"2",
"3",
"4",
"5",
"6"
]
}
]
} );

To be clear I have:
{
label: "Certify",
name: "level_id",
type: "select",
options: [
{ label: 'New', value: "1" },
{ label: 'Pending', value: '6' },
{ label: 'Certified', value: '2' },
]
},

Which works once you click in field that displays the number it brings up the drop down but I need the drop down label to be in the field not number when the page is loaded.

I am new to Javascript how do I get the labels to show up for the end user and not the number that needs to be submitted?

Any help or an example would be appreciated!

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,627Questions: 1Answers: 10,090 Site admin

    Yes, Generator is limited here, but it is designed as a quick start tool only. Editor is capable of a lot more than what Generator shows. You've done the right thing to use objects with label and value for Editor.

    You would need to then use a renderer for the table which would convert the numeric value into a label.

    If you have a lot of options that can get fairly long winded, so an option is to use joins which make the label / value more transparent (example).

    Regards,
    Allan

  • TwiggitTwiggit Posts: 11Questions: 4Answers: 0

    Thanks for the quick response and for pointing me in the right direction Allan. I will read the docs and hopefully I can work it!

    I have never been a fan of client side programing but from what I have seen so far Editor is amazing!

  • TwiggitTwiggit Posts: 11Questions: 4Answers: 0

    Hi Allan,

    Is there a complete example of using a pull down menu in Editor where the server returns a value as a number and "labels" are rendered in text as the menu choices?

  • allanallan Posts: 61,627Questions: 1Answers: 10,090 Site admin

    Yes, the join example uses this method.

    Allan

  • TwiggitTwiggit Posts: 11Questions: 4Answers: 0

    Hi Allan,

    This sort of worked but now my problem is I need to be able to generate the pull down but using a condition. For example the table I am joining to has an id field, a field for name and a field for region.

    It joins the primary table on id and I am using a where clause to limit the results by the region number.

    The problem is the where clause properly limits the result set but does not limit the result set of the joined table so the pull down had all the entries not just the one from a particular region.

    Its confusing I know... here is my code it might help you see what I am doing wrong:

    Editor::inst( $db, 'primary_profile', 'uid' )
    ->field(
    Field::inst( 'primary_profile.fName' ),
    Field::inst( 'primary_profile.lName' ),
    Field::inst( 'certification.sm_rec' ),
    Field::inst( 'attributes.access' ),
    Field::inst( 'attributes.teaching' ),
    Field::inst( 'primary_profile.mentorId' )
    ->options( 'mentors', 'mentorId', 'men_fullName' )
    ->validator( 'Validate::dbValues' ),
    Field::inst( 'mentors.men_fullName' )
    )
    ->leftJoin( 'attributes', 'attributes.uid', '=', 'primary_profile.uid' )
    ->leftJoin( 'certification', 'certification.uid', '=', 'primary_profile.uid' )
    ->leftJoin( 'mentors', 'mentors.mentorId', '=', 'primary_profile.mentorId' )
    ->where( function ( $q ) {
    $q
    ->where('primary_profile.nid', 32);
    } )
    ->process($_POST)
    ->json();

    Thanks for taking the time Allan

  • allanallan Posts: 61,627Questions: 1Answers: 10,090 Site admin
    Answer ✓

    Hi,

    The optional fourth parameter for the Field->options() method can be used to specify a condition for the options. Details about this are available in the documentation here.

    Regards,
    Allan

  • TwiggitTwiggit Posts: 11Questions: 4Answers: 0
    edited October 2016

    Oh I missed this still trying to wrap my mind around the optional functions not knowing much JavaScript.

This discussion has been closed.