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

  • 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.
  • 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)
  • Hi Nick,

    I might be missing something from your question, but you tried to add the dropdown items into a local array variable and if they try to add new item then check against the local variable?
  • 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.
  • yes i've added both set of variables in a local var, and i'm validating on the grid by using the contains() in a separate Expr rule. It's just the validation doesn't go right as it tries to validate existing data which has similar data.
  • As per your it's just a selection of a radio button that loads the grid, if there are no existing items they may be added.
    I would suggest you to use two variables one is for selectingValues another is for already selected values. So, upon clicking on radio button you can check in the already selected values list for the clicked item. then you can say display a message "This item already selected". If you don't want to show the message and still want to maintain the unique list items, simply apply the union() on the both selected lists.
  • how large is the dropdown and grid you will be validating against? The efficacy and performance of some of the suggested solutions will vary depending on that.
  • Hi,

    I hope below code is useful to you

    load(
    local!data:{"data","data1","data2","data3","data4"},
    {
    a!gridLayout(
    label: " Grid",
    labelPosition: "ABOVE",
    headerCells: {
    a!gridLayoutHeaderCell(label: "Data Name")
    },
    columnConfigs: {},
    rows: {
    a!forEach(
    items: local!data,
    expression:
    a!gridRowLayout(
    contents: {
    a!textField(
    value: fv!item,
    saveInto:{ri!data,
    a!save(ri!data,"Data")}
    )
    }
    )
    )

    },
    selectionSaveInto: {},
    validations: {},
    shadeAlternateRows: true
    ),

    a!buttonLayout(
    secondaryButtons: a!buttonWidget(
    label: "Covert",
    saveInto: ri!update_Btn,
    value: "True"
    )
    ),
    a!sectionLayout(
    showWhen: ri!update_Btn="true",
    contents: {
    a!dropdownField(
    label: "",
    placeholderLabel: "Provide grid data",
    choiceLabels: local!data,
    choiceValues:local!data,
    saveInto: ri!data,
    value: ri!data

    )
    }
    )

    }
    )

    Thanks,
    Devi.
  • 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.