Is there a way to allow null values in a join-column with type: select?

Is there a way to allow null values in a join-column with type: select?

HolmbergMaHolmbergMa Posts: 3Questions: 1Answers: 0

When setting up a column with a foregin key I want the select dropdown to include a null option in addition to every value in the related table. Is this possible?
I've set up my table on both server side and client side according to this page: https://editor.datatables.net/manual/php/joins

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    Editor 1.5.4 has a new placeholder option for the select field type. That can be used to add an "No item selected" type of option. Also use the placeholderDisabled option to allow the end user to select it.

    I would suggest having the placeholder value as an empty string and then at the server use a set formatter (ifEmpty) to write a null into the database when the empty string is found.

    It might sound a little complicated, but its just a couple of additional lines of code :-)

    Allan

  • HolmbergMaHolmbergMa Posts: 3Questions: 1Answers: 0
    edited December 2015

    Thanks Allan!
    I think that this solution will fit my needs perfectly!
    However now I think that I have issues with the syntax for the placeholder and placeholderDisabled options.
    I tried what I thought was the logical approach to add the options in the field-array which i use in the call when i create the editor instance.

    { label: labelName,

    name: fieldName,

    type: "select",

    placeholderDisabled: false,

    placeholder: "placeholderText"}

    Is this correct or do I need to create my field first and then use the field().update( options ) to add the placeholder?

  • HolmbergMaHolmbergMa Posts: 3Questions: 1Answers: 0
    edited December 2015

    I was running an older version of Editor...

    With Editor 1.5.4 it now works Perfectly!

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Thanks for posting back - good to hear the new version works well for you!

    Regards,
    Allan

This discussion has been closed.