Validate grid items against drop down values.

Hello guys,

            I've an interface where I need to validate a grid items added by user in a gridfield and once they submit they become available for selection in the dropdown on the same interface where once they select the item they can submit finally.

 

            Has anyone ever had tried validating add/removable grid items against the existing dropdown (populated by the same gridfield) to make sure they do not enter the "duplicate" values?

 

Thanks,

Nick

  Discussion posts and replies are publicly visible

Parents
  • Nick,

    On the entry form, where they need to add new items, I would add a validation to ensure that the entered value is not already existing in the DB. On "Submit", I would query the DB for the item name, and if the totalcount of the resulting datasubset is greater than 0, then return an error message to the user indicating that an item with that name already exists. Depending on the number of values in the DB and performance constraints, you could use a simpler, but less performant method of querying for all existing items on page load, and on "Keypress" find the entered value within the existing list. If a match is found, return a similar error message.

    If you need additional support, please post your code, and we can provide more concrete code suggestions, but this is the method I would use to validate the entered values.
Reply
  • Nick,

    On the entry form, where they need to add new items, I would add a validation to ensure that the entered value is not already existing in the DB. On "Submit", I would query the DB for the item name, and if the totalcount of the resulting datasubset is greater than 0, then return an error message to the user indicating that an item with that name already exists. Depending on the number of values in the DB and performance constraints, you could use a simpler, but less performant method of querying for all existing items on page load, and on "Keypress" find the entered value within the existing list. If a match is found, return a similar error message.

    If you need additional support, please post your code, and we can provide more concrete code suggestions, but this is the method I would use to validate the entered values.
Children
  • Hello Ashvin, thanks for you suggestion. But we've an issue with the querying on the db side, it'll make the interface slower. My instructions are to validate the gridfield inputs against the dropdown component. the setup of the page isn't that complex, it's just a selection of a radio button that loads the grid, if there are no existing items they may be added, those items when the 'Update' button is pressed are visible as dropdown ChoiceValues and the user can then select the value they may choose to finally 'submit'.
  • So once you click update, whatever was entered are now available as choiceLabels and choiceValues. That means, you're saving the inputted values to a variable. Couldn't you just run a contains() function to check if the new value is within that variable? contains(ri!previouslyInputtedValues, local!newInputtedValue)
  • Yes apparently that's exactly my code. But the problem is whenever the grid loads with may be an existing item, thats when the the validation error message gets triggered as it can detect the data in both grid as well as the dropdown choiceValues. Data has been converted to regular text using touniformstring() but my problem is there's no way I can validate the new grid data against the dropdown as the validation for the existing data (where previously entered data will be similar in both components) gets triggered.
  • Delayed reply sorry finally got time to work on this, But yeah index func and where index item is wherecontains instead of contains() (gives boolean right, so no game there!) and sort of used other people's idea but it finally worked out. Validating duplicate items on dropdown for just one entry selection felt like there should be an out of box func to resolve such queries.