how to show the different required message for the same field?

Certified Senior Developer

Hi,

We have requirement like need to show different required message(dynamic message) for a particular field based on two different button clicks.

here are the more details like we have one comments field which is required for both the submit buttons with names like "Add More Info" and "Add More Comments" .

when the user clicks on "Add More Info" button without providing the comments then need to show the required message is like "comments required for More Information".

when the user clicks on "Add More Comments" button without providing the data to comments field then need to show the required message like "comments should not be blank"

 

Can some one suggest any way to achieve this...

-Ram

  Discussion posts and replies are publicly visible

Parents
  • Hello Ramp,

    I agree with Mike, the logic should not rely on the button that is pressed why don't you just add the default message or a generic.

    Here is an example how the solution can be.  If you have more fields then this is not going to work as is. 

     

    load(
      local!text: "",
      local!tmpButton,
      a!formLayout(
        contents: a!columnsLayout(
          columns: {
            a!columnLayout(
              contents: {
                a!paragraphField(
                  label: "Comment" ,
                  value: local!text,
                  saveInto: local!text,
                  /*refreshAfter: "KEYPRESS",*/
                  required: not(rule!APN_isBlank(local!tmpButton)),/* < -- Note this*/ 
                  validationGroup: "submit save"
                ), 
                a!richTextDisplayField(/* < -- Note this*/ 
                  showWhen: and (
                      not(rule!APN_isBlank(local!tmpButton)), 
                      rule!APN_isBlank(local!text)
                  ),
                  value:a!richTextItem(
                    text:a!richTextItem(
                      text:if(
                        local!tmpButton = "save",
                        "Please add comment on save",
                        "Please add Note on submit"
                      ),
                      style: "NEGATIVE"
                    ),
                    style: "STRONG"
                  )
                )
              }
            )
          }
        ),
        validations: {},
        buttons: a!buttonlayout(
          primaryButtons: {
            a!buttonWidget(
              showWhen: rule!APN_isBlank(local!text),
              saveInto: local!tmpButton,
              label: "submit Widget",
              value: "submit",
              style: "PRIMARY"
            ),
            a!buttonWidget(
              showWhen: rule!APN_isBlank(local!text),
              saveInto: local!tmpButton,
              label: "save Widget",
              value: "save",
              style: "SECONDARY"
            ),
            a!buttonWidgetSubmit(
              showWhen: not(rule!APN_isBlank(local!text)),
              saveInto: ri!button,
              validationGroup: "submit",
              label: "submit Submit",
              value: "submit",
              style: "PRIMARY"
            ),
            a!buttonWidgetSubmit(
              showWhen: not(rule!APN_isBlank(local!text)),
              saveInto: ri!button,
              label: "save Submit",
              value: "save",
              validationGroup: "save",
              style: "SECONDARY"
            )
          }
        )
      )
    )

    Jose

Reply
  • Hello Ramp,

    I agree with Mike, the logic should not rely on the button that is pressed why don't you just add the default message or a generic.

    Here is an example how the solution can be.  If you have more fields then this is not going to work as is. 

     

    load(
      local!text: "",
      local!tmpButton,
      a!formLayout(
        contents: a!columnsLayout(
          columns: {
            a!columnLayout(
              contents: {
                a!paragraphField(
                  label: "Comment" ,
                  value: local!text,
                  saveInto: local!text,
                  /*refreshAfter: "KEYPRESS",*/
                  required: not(rule!APN_isBlank(local!tmpButton)),/* < -- Note this*/ 
                  validationGroup: "submit save"
                ), 
                a!richTextDisplayField(/* < -- Note this*/ 
                  showWhen: and (
                      not(rule!APN_isBlank(local!tmpButton)), 
                      rule!APN_isBlank(local!text)
                  ),
                  value:a!richTextItem(
                    text:a!richTextItem(
                      text:if(
                        local!tmpButton = "save",
                        "Please add comment on save",
                        "Please add Note on submit"
                      ),
                      style: "NEGATIVE"
                    ),
                    style: "STRONG"
                  )
                )
              }
            )
          }
        ),
        validations: {},
        buttons: a!buttonlayout(
          primaryButtons: {
            a!buttonWidget(
              showWhen: rule!APN_isBlank(local!text),
              saveInto: local!tmpButton,
              label: "submit Widget",
              value: "submit",
              style: "PRIMARY"
            ),
            a!buttonWidget(
              showWhen: rule!APN_isBlank(local!text),
              saveInto: local!tmpButton,
              label: "save Widget",
              value: "save",
              style: "SECONDARY"
            ),
            a!buttonWidgetSubmit(
              showWhen: not(rule!APN_isBlank(local!text)),
              saveInto: ri!button,
              validationGroup: "submit",
              label: "submit Submit",
              value: "submit",
              style: "PRIMARY"
            ),
            a!buttonWidgetSubmit(
              showWhen: not(rule!APN_isBlank(local!text)),
              saveInto: ri!button,
              label: "save Submit",
              value: "save",
              validationGroup: "save",
              style: "SECONDARY"
            )
          }
        )
      )
    )

    Jose

Children