Restrict quantity in List or Library Control

Hello,

I have a list or library control on my main form that contains a dropdown called 'Items' that has lookup values. When a user selects 'Face shields' from the Items dropdown, i would like to restrict the value in the 'Quantity' field to 1.

My code isn't working:

fd.spRendered(function() {

fd.control('SPDataTable1').$on('edit', function(editData) {

  editData.field('Quantity').validators.push({

    name: 'MyCustomValidator2',

    error: '',

    validate: function(value) {

        if (editData.field('Item').value == 'Face shields') {

            if (value >= 1) {

                this.error = 'Please select a quantity of 1';

                return false;

            }

        }

        return true;

    }

  });

});

});

Hello @ParAvion,

Lookup field value stores as an object. To get the selected value as a string you should use this code:

editData.field('Item').value.LookupValue

Please find more information about the lookup field properties here.

The updated code would be:

 fd.control('SPDataTable1').$on('edit', function(editData) {

      editData.field('Quantity').validators.push({

        name: 'MyCustomValidator2',

        error: '',

        validate: function(value) {
             //returns the selected element as a string
            if (editData.field('Item').value.LookupValue == 'Face shields') {

                if (value >= 1) {

                    this.error = 'Please select a quantity of 1';

                    return false;

                }

            }

            return true;

        }

      });

  });

Hello,

I was never able to get this working. Any ideas?

Code:
image

@ParAvion,

Are you getting any errors in the browser console(F12)?

Please share the complete code that you are using.