How to check the options of a select field

How to check the options of a select field

rf1234rf1234 Posts: 2,993Questions: 87Answers: 421

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: 63,516Questions: 1Answers: 10,472 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,993Questions: 87Answers: 421

    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,993Questions: 87Answers: 421

    @allan , what can I do about this please?

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    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,993Questions: 87Answers: 421

    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: 63,516Questions: 1Answers: 10,472 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,993Questions: 87Answers: 421

    thanks a lot!!!

This discussion has been closed.