How to check the options of a select field

How to check the options of a select field

rf1234rf1234 Posts: 2,801Questions: 85Answers: 406

Can I programmatically check the options of a select field?
e.g. whether the options are equal to an empty array?
https://editor.datatables.net/reference/field/select

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,438Questions: 1Answers: 10,050 Site admin

    By "check" do you mean read the currently selected values? If so, then yes - the field().val() method will get you the currently selected value(s).

    Allan

  • rf1234rf1234 Posts: 2,801Questions: 85Answers: 406

    No, I mean the options that the user can choose from with the select field. I set them dynamically and it may happen that the user cannot select anything because there are no options available.

  • rf1234rf1234 Posts: 2,801Questions: 85Answers: 406

    @allan , what can I do about this please?

  • tangerinetangerine Posts: 3,342Questions: 35Answers: 394
    edited January 2018

    @rf1234 :
    A ) where are your select options coming from?
    B ) what do you want to show the user if there are no options?

  • rf1234rf1234 Posts: 2,801Questions: 85Answers: 406

    a) ajax call to server script
    b) customized message in Editor window

    Would like to check whether there are no options and then display the message. Right now I can't do the check and ALWAYS have to show a message like "in case your contract only comprises 'productxyz' you will not be able to select an option".

  • allanallan Posts: 61,438Questions: 1Answers: 10,050 Site admin
    Answer ✓

    Oh - you want to "check what values are in the select field"?

    In that case use field().input() with a little jQuery to get the options:

    editor.field('myField').input().find('option');
    

    that will give you a jQuery object of the option elements in the select element.

    Allan

  • rf1234rf1234 Posts: 2,801Questions: 85Answers: 406

    thanks a lot!!!

This discussion has been closed.