Search text in cdt

 Hi,

I have a cdt which is having more than 100 rows with 12 columns. I want to create one validation on submit button where i want to check duplicacy of each column value respective to all column values.

Like           Column

         A B C D E F G H I J K

Row1   1 2 3 4 5 6 7 8 9 10

Row2   11 12 13 14 16 17 18

Row3  19 20 21 22 23 24 25

My cdt is like above data. If i add new row than value of each column should be unique to all columns .

 

Kindly share any optimize solution which i can use on submit button .

  Discussion posts and replies are publicly visible

Parents
  • Here you go - pretty sure this does what you want - paste it into the interface designer and see what you think.

    load(
      local!data: a!forEach(
        items: enumerate(
          5
        ) + 1,
        expression: {
          "A": 1 + (
            (
              fv!item - 1
            ) * 10
          ),
          "B": 2 + (
            (
              fv!item - 1
            ) * 10
          ),
          "C": 3 + (
            (
              fv!item - 1
            ) * 10
          ),
          "D": 4 + (
            (
              fv!item - 1
            ) * 10
          ),
          "E": 5 + (
            (
              fv!item - 1
            ) * 10
          ),
          "F": 6 + (
            (
              fv!item - 1
            ) * 10
          ),
          "G": 7 + (
            (
              fv!item - 1
            ) * 10
          ),
          "H": 8 + (
            (
              fv!item - 1
            ) * 10
          ),
          "I": 9 + (
            (
              fv!item - 1
            ) * 10
          ),
          "J": 10 + (
            (
              fv!item - 1
            ) * 10
          )
        }
      ),
      a!formLayout(
        label: "Validate search text",
        contents: {
          a!paragraphField(
            labal: "local!data",
            value: local!data
          ),
          a!gridLayout(
            label: "HALP",
            headerCells: {
              a!gridLayoutHeaderCell(
                label: "A"
              ),
              a!gridLayoutHeaderCell(
                label: "B"
              ),
              a!gridLayoutHeaderCell(
                label: "C"
              ),
              a!gridLayoutHeaderCell(
                label: "D"
              ),
              a!gridLayoutHeaderCell(
                label: "E"
              ),
              a!gridLayoutHeaderCell(
                label: "F"
              ),
              a!gridLayoutHeaderCell(
                label: "G"
              ),
              a!gridLayoutHeaderCell(
                label: "H"
              ),
              a!gridLayoutHeaderCell(
                label: "I"
              ),
              a!gridLayoutHeaderCell(
                label: "J"
              )
            },
            columnConfigs: {
              a!gridLayoutColumnConfig(
                weight: 5
              ),
              a!gridLayoutColumnConfig(
                weight: 5
              ),
              a!gridLayoutColumnConfig(
                weight: 5
              ),
              a!gridLayoutColumnConfig(
                weight: 5
              ),
              a!gridLayoutColumnConfig(
                weight: 5
              ),
              a!gridLayoutColumnConfig(
                weight: 5
              ),
              a!gridLayoutColumnConfig(
                weight: 5
              ),
              a!gridLayoutColumnConfig(
                weight: 5
              ),
              a!gridLayoutColumnConfig(
                weight: 5
              ),
              a!gridLayoutColumnConfig(
                weight: 5
              )
            },
            rows: a!forEach(
              items: local!data,
              expression: a!gridRowLayout(
                contents: {
                  a!textField(
                    value: fv!item.A,
                    saveInto: fv!item.A,
                    required: true,
                    validationGroup: "runValidation",
                    validations: if(
                      contains(
                        touniformstring(
                          a!flatten(
                            {
                            remove(
                              local!data.A,
                              fv!index
                            ),
                            local!data.B,
                            local!data.C,
                            local!data.D,
                            local!data.E,
                            local!data.F,
                            local!data.G,
                            local!data.H,
                            local!data.I,
                            local!data.J
                            }
                          )
                        ),
                        tostring(
                          fv!item.A
                        )
                      ),
                      "This value already exists in the data",
                      ""
                    )
                  ),
                  a!textField(
                    value: fv!item.B,
                    saveInto: fv!item.B,
                    required: true,
                    validationGroup: "runValidation",
                    validations: if(
                      contains(
                        touniformstring(
                          a!flatten(
                            {
                            local!data.A,
                            remove(
                              local!data.B,
                              fv!index
                            ),
                            local!data.C,
                            local!data.D,
                            local!data.E,
                            local!data.F,
                            local!data.G,
                            local!data.H,
                            local!data.I,
                            local!data.J
                            }
                          )
                        ),
                        tostring(
                          fv!item.B
                        )
                      ),
                      "This value already exists in the data",
                      ""
                    )
                  ),
                  a!textField(
                    value: fv!item.C,
                    saveInto: fv!item.C,
                    required: true,
                    validationGroup: "runValidation",
                    validations: if(
                      contains(
                        touniformstring(
                          a!flatten(
                            {
                            local!data.A,
                            local!data.B,
                            remove(
                              local!data.C,
                              fv!index
                            ),
                            local!data.D,
                            local!data.E,
                            local!data.F,
                            local!data.G,
                            local!data.H,
                            local!data.I,
                            local!data.J
                            }
                          )
                        ),
                        tostring(
                          fv!item.C
                        )
                      ),
                      "This value already exists in the data",
                      ""
                    )
                  ),
                  a!textField(
                    value: fv!item.D,
                    saveInto: fv!item.D,
                    required: true,
                    validationGroup: "runValidation",
                    validations: if(
                      contains(
                        touniformstring(
                          a!flatten(
                            {
                            local!data.A,
                            local!data.B,
                            local!data.C,
                            remove(
                              local!data.D,
                              fv!index
                            ),
                            local!data.E,
                            local!data.F,
                            local!data.G,
                            local!data.H,
                            local!data.I,
                            local!data.J
                            }
                          )
                        ),
                        tostring(
                          fv!item.D
                        )
                      ),
                      "This value already exists in the data",
                      ""
                    )
                  ),
                  a!textField(
                    value: fv!item.E,
                    saveInto: fv!item.E,
                    required: true,
                    validationGroup: "runValidation",
                    validations: if(
                      contains(
                        touniformstring(
                          a!flatten(
                            {
                            local!data.A,
                            local!data.B,
                            local!data.C,
                            local!data.D,
                            remove(
                              local!data.E,
                              fv!index
                            ),
                            local!data.F,
                            local!data.G,
                            local!data.H,
                            local!data.I,
                            local!data.J
                            }
                          )
                          
                        ),
                        tostring(
                          fv!item.E
                        )
                      ),
                      "This value already exists in the data",
                      ""
                    )
                  ),
                  a!textField(
                    value: fv!item.F,
                    saveInto: fv!item.F,
                    required: true,
                    validationGroup: "runValidation",
                    validations: if(
                      contains(
                        touniformstring(
                          a!flatten(
                            {
                            local!data.A,
                            local!data.B,
                            local!data.C,
                            local!data.D,
                            local!data.E,
                            remove(
                              local!data.F,
                              fv!index
                            ),
                            local!data.G,
                            local!data.H,
                            local!data.I,
                            local!data.J
                            }
                          )
                          
                        ),
                        tostring(
                          fv!item.F
                        )
                      ),
                      "This value already exists in the data",
                      ""
                    )
                  ),
                  a!textField(
                    value: fv!item.G,
                    saveInto: fv!item.G,
                    required: true,
                    validationGroup: "runValidation",
                    validations: if(
                      contains(
                        touniformstring(
                          a!flatten(
                            {
                            local!data.A,
                            local!data.B,
                            local!data.C,
                            local!data.D,
                            local!data.E,
                            local!data.F,
                            remove(
                              local!data.G,
                              fv!index
                            ),
                            local!data.H,
                            local!data.I,
                            local!data.J
                            }
                          )
                          
                        ),
                        tostring(
                          fv!item.G
                        )
                      ),
                      "This value already exists in the data",
                      ""
                    )
                  ),
                  a!textField(
                    value: fv!item.H,
                    saveInto: fv!item.H,
                    required: true,
                    validationGroup: "runValidation",
                    validations: if(
                      contains(
                        touniformstring(
                          a!flatten(
                            {
                            local!data.A,
                            local!data.B,
                            local!data.C,
                            local!data.D,
                            local!data.E,
                            local!data.F,
                            local!data.G,
                            remove(
                              local!data.H,
                              fv!index
                            ),
                            local!data.I,
                            local!data.J
                            }
                          )
                          
                        ),
                        tostring(
                          fv!item.H
                        )
                      ),
                      "This value already exists in the data",
                      ""
                    )
                  ),
                  a!textField(
                    value: fv!item.I,
                    saveInto: fv!item.I,
                    required: true,
                    validationGroup: "runValidation",
                    validations: if(
                      contains(
                        touniformstring(
                          a!flatten(
                            {
                            local!data.A,
                            local!data.B,
                            local!data.C,
                            local!data.D,
                            local!data.E,
                            local!data.F,
                            local!data.G,
                            local!data.H,
                            remove(
                              local!data.I,
                              fv!index
                            ),
                            local!data.J
                            }
                          )
                          
                        ),
                        tostring(
                          fv!item.I
                        )
                      ),
                      "This value already exists in the data",
                      ""
                    )
                  ),
                  a!textField(
                    value: fv!item.J,
                    saveInto: fv!item.J,
                    required: true,
                    validationGroup: "runValidation",
                    validations: if(
                      contains(
                        touniformstring(
                          a!flatten(
                            {
                            local!data.A,
                            local!data.B,
                            local!data.C,
                            local!data.D,
                            local!data.E,
                            local!data.F,
                            local!data.G,
                            local!data.H,
                            local!data.I,
                            remove(
                              local!data.J,
                              fv!index
                            )
                            }
                          )
                          
                        ),
                        tostring(
                          fv!item.J
                        )
                      ),
                      "This value already exists in the data",
                      ""
                    )
                  )
                }
              )
            ),
            addRowLink: a!dynamicLink(
              label: "Add row",
              value: {
                "A": null,
                "B": null,
                "C": null,
                "D": null,
                "E": null,
                "F": null,
                "G": null,
                "H": null,
                "I": null,
                "J": null
              },
              saveInto: a!save(
                target: local!data,
                value: append(
                  local!data,
                  save!value
                )
              )
            )
          )
        },
        buttons: a!buttonLayout(
          primaryButtons: {
            a!buttonWidgetSubmit(
              label: "Save",
              validationGroup: "runValidation"
            )
          }
        )
      )
    )

  • Thanks for your inputs.

    But this solution is in my knowledge.

    Requirement is bit different , here searching need to perform on all values irrespective of any column, in your code it is searching at column level plus i want this to perform on submit button not at the row level .
  • 0
    A Score Level 1
    in reply to sauravk
    No problem - code updated.

    Your requirement to only validate when the button is pressed is possible - just use an a!validationMessage() on the grid with a validateAfter: "SUBMIT". However, if you were to do that, and remove the individual field validation, you'll end up with an extremely poor user experience as there won't be any highlighting of fields to show which values in the grid are duplicated - hence I'd recommend you follow the example given.
  • Thanks for your inputs. Really helped to kick off this work. Your approach is correct. I will try to go by that only.
    Will keep you posted if i need more inputs.
  • 0
    A Score Level 1
    in reply to sauravk
    No problem, glad I could help! :)
  • Is it possible to modify this code to validate one more condition. Like if we want to validate data in pairs.
    Suppose i want to validate only two columns (A & B) , combination of these two columns only should be unique.
    If yes than please suggest me.
Reply Children
No Data