Set validator for lookup dropdown

Hi,

I want to have a validator for a lookup dropdown called 'Item' in a list or library control. Users should be required to select an item from the dropdown menu (cannot be blank). I've tried using the code below but it's not working for me. Thoughts?

image

Thanks.

Hello @ParAvion ,

You need to change the condition to:

if(!value) {
   return false;
}

@mnikitina thanks I've updated to this but there's still no validator on 'Item'..

image

@ParAvion,

Please also specify the error message:

fd.control('SPDataTable1').$on('edit', function(editData) {
    editData.field('Item').validators.push({
      name: 'MyCustomValidator',
      error: 'Error Message',
      validate: function(value) {
          if (!value) {
            return false;
          }
          return true;
      }
    });
});

@mnikitina strange...it's still not working. Does it matter that "Item" is a lookup dropdown?

The form will let users save the list or library control without selecting an item:

@ParAvion,

What version of the desktop designer and the app package are you using?

Please try to comment out all code except the one to validate the 'Item' field. Clear the browser cache and try again.

If the validation doesn't work, check are there any errors in the browser console(F12) and share the screenshot.

@mnikitina I was able to get it working using the code below. Thanks.

image

1 Like