Removing items from a drop down

Removing items from a drop down

rob1strob1st Posts: 84Questions: 22Answers: 0

I have removed items from a drop down using the code below, just wondering instead of listing each option, is there a way of saying hide all values above 3?

I could not just just use a WHERE on the controller because I want people to see the status when it is above 3, just not be able to set it to anything above 3.

Thoughts?

editor.dependent('A.assetStatus', function(val, data, callback) {
    if (val > 3) {
      editor.disable('A.assetStatus');
    } else {
      editor.enable('A.assetStatus');
      $('#DTE_Field_A-assetStatus').find('option[value="4"]').hide();   
      $('#DTE_Field_A-assetStatus').find('option[value="5"]').hide();   
      $('#DTE_Field_A-assetStatus').find('option[value="6"]').hide();   
      $('#DTE_Field_A-assetStatus').find('option[value="7"]').hide();   
      $('#DTE_Field_A-assetStatus').find('option[value="8"]').hide();   
      $('#DTE_Field_A-assetStatus').find('option[value="9"]').hide();   
      $('#DTE_Field_A-assetStatus').find('option[value="10"]').hide();  
      $('#DTE_Field_A-assetStatus').find('option[value="11"]').hide();  
    } 
    callback(true);
  });

This question has an accepted answers - jump to answer

Answers

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

    jQuery's filter is probably the best way to do it:

    $('#DTE_Field_A-assetStatus option')
      .filter(function () {
        return parseInt($(this).attr('value'), 10) <= 3;
      })
      .hide();
    

    Allan

  • rob1strob1st Posts: 84Questions: 22Answers: 0

    Thanks Allan

  • rob1strob1st Posts: 84Questions: 22Answers: 0

    Interesting, I thought this worked, but it didn't after all.

    I assumed what you have put goes into the else side of the if statement after the editor.enable('A.assetStatus'); but it didn't work.

    Am I missing something Allan?

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

    Nothing obvious that I can see! Perhaps you can give me a link to a page showing the issue? This is when the Editor form is shown? If it is hidden you would need to use field().input() to get the select element (which is probably a good idea anyway).

    Allan

Sign In or Register to comment.