How to check the options of a select field

How to check the options of a select field

rf1234rf1234 Posts: 564Questions: 37Answers: 82

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: 45,699Questions: 1Answers: 6,272 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: 564Questions: 37Answers: 82

    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: 564Questions: 37Answers: 82

    @allan , what can I do about this please?

  • tangerinetangerine Posts: 2,040Questions: 12Answers: 226
    edited January 12

    @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: 564Questions: 37Answers: 82

    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: 45,699Questions: 1Answers: 6,272 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: 564Questions: 37Answers: 82

    thanks a lot!!!

Sign In or Register to comment.