How can I add a "None" (null) option to a dropdown that uses inline editor on a left join table.

How can I add a "None" (null) option to a dropdown that uses inline editor on a left join table.

OtherJasonOtherJason Posts: 5Questions: 1Answers: 0

How can I add a "None" (null) option to a dropdown/Select that uses inline editor on a left join table. The field itself is nullable and there are instances where a user may want to go back to the null state. How can I add this option to the select list that the editor generates? I am using .Net, Datatables 1.10.18 and editor 1.9.0.

Thank you

This question has accepted answers - jump to:

Answers

  • airmasterairmaster Posts: 72Questions: 15Answers: 2
    Answer ✓

    Can you add this to the fields definition?

                            type: "select",
                            placeholder: "-- None/Select --",
    
  • allanallan Posts: 61,669Questions: 1Answers: 10,096 Site admin
    Answer ✓

    In addition to the placeholder option there are placeholderDisabled and placeholderValue options for the select field type. They can be used to allow a default placeholder to be selectable and have a specific value.

    Note that if you want a null in the database, set the placeholderValue to be an empty string an use a set formatter on the server-side to change that into null.

    Allan

  • lifestylelifestyle Posts: 20Questions: 5Answers: 0

    This works fine on a new empty record using the editor, but since the drop down values are coming from the server side as options data in the JSON, there is not empty / null option when editing the record. How do we add an empty choice the dynamically created select list from the LEFTJOINS used to create the JSON for the editor?

  • allanallan Posts: 61,669Questions: 1Answers: 10,096 Site admin

    I'm not quite following I'm afraid - do you want to dynamically turn the placeholder* options on an off? Or are you just looking to change the list of options between create and edit? If the latter, then field().update() can be used to change the list of options, and initEdit and initCreate used to tell between the two actions. For the former, there is no option to dynamically change the placeholder options at this time.

    Allan

  • lifestylelifestyle Posts: 20Questions: 5Answers: 0
    edited January 2021

    It was the latter. I wanted to inject a new "null" or empty value into the list (which is obtained from the options section of the JSON stemming from the query). It doesn't have an empty/null option in that data set so I need to include one, or a way to unset the current value upon editing. Create is easy since the placeholder is null and works fine. I will take a stab at the field update method.

    The goal is to let someone edit and unset a previously selected value from a select list.

    Ultimately I want to make each select chained (maybe with a server side ajax call so I don't preload all the possible options each time) so as to refine the available options for the next select during create and edit - including a way to unset a value so that edits can be made using that chained workflow. I have not searched on how to pull that off yet. Thanks for the feedback on this older thread.

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    This example here might help - it's adding the office location to the select if it wasn't in the list when editing starts. You could perhaps do something like that for the empty value.

    Colin

This discussion has been closed.