Need to make a field is required for a button which has skipped all the validation including this field.

I have a button which has skipped all rule input field validation on one interface. Right now, I want to get a warning when I click the button without a specific rule input field value. 

I couldn't use validationGroup directly because I have made this specific rule input field is mandatory for one more button on the same interface.

Like the example code below, I want to get a warning "text1 is mandatory" when I click the button1. And text1 and text2 are still mandatory field for button2.

load(
  local!button1,
  local!button2,
  local!text1,
  local!text2,
  a!formLayout(
    firstcolumnContents:{
      a!textfield(
        lable: "text1",
        required: true,
        value: local!text1,
        ssaveInto: local!text1
      )
    },
    secondcolunmContents:{
      a!textfield(
        label: "texx2",
        require: true,
        value: local!text2,
        saveInto: local!text2
      )
    },
    buttons: a!buttonlayout:{
    primaryButton:{
 a!buttonWidegetSubmit(
          label: "button1",
          value: true,
          saveInto: local!button1,
          skipvalidation: true
        ),
        a!buttonWidgetSubmit(
          lable: "button2",
          value: false,
          saveInto: local!button2
        )
      }
    }
  )
)

  Discussion posts and replies are publicly visible

  • Hi -

    I'm not sure I understand your use case 100%.
    But, your description reminds me of a design decision my team once made when validations started to get very complex.
    Essentially, we did skipvalidation on everything, and then validated the form in process after it was submitted.
    If the form was invalid, we still saved all the data that was entered, but the user could not complete the business process. And, that status was indicated visually to the user.
    They would be able to revisit the form later via a related action on the record.

    This was a specific use case for a business process that included a number of "stage gates" where large blocks of data could be entered and saved in any order, but the user could go to the next stage until the current stage was complete.
    This might, or might not be appropriate for you.
  • Hi Tony,

    you can do this in process model after form submission.

    Just follow the below steps :

    1) create one rule input for the interface (isValid ) and set it boolean.
    2) use this bool in the textfield1,required property required=if(ri!isValid=true(),true(),false())
    3) Now in the process model after form submission, check the which button is clicked if button2 then set the isVaid=true and return the step again the same interface with the variable value then you will get warning message or required field message.

    Regards
    Abhay
  • 0
    Certified Senior Developer
    Hi
    did you tried with confirmationMassage ?
  • 0
    Certified Lead Developer
    Unfortunately there's no easy solution to this use case, and I have always found validationGroups a neverending rabbit hole of frustration and disappointment. I would agree with some of the prior commentors that post-form validation might be the best way to implement exactly what you're asking for.

    However I would suggest maybe you could restructure your logic slightly. Honestly, waiting until a button click event to decide that a specific field is "required" is too late - for the reasons you've already run into. Why do you need 2 separate buttons, where one of them ignores that field and the other makes it required? Could you instead transition that logic into some selector (radio / checkbox) on-form that distinguishes between the use cases? In this case, you would only have *one* action button, and its action would be determined partly by the value of the aforementioned selector. The major benefit here would be that you could set the "required" value of the sometimes-required field to be required when the conditions are correct (i.e. the selector is set to one particular position).
  • 0
    Certified Lead Developer
    I agree with Mike. The best solution would be to re-structure your logic and keep it as simple as possible. This will not only make the implementation easy to use but also help in easy maintenance.
  • Thank you for you suggestion. I agree that using validationGroup is endless rabbit hole and I can't satisfy the requirements with it. The reason to have two button is because one is for save the value as a draft and another one is for submitting the value to next person. It is necessary to have two buttons because of the requirement. I will try to re-structure the logic if I could not find a way to fix it.
  • 0
    Certified Lead Developer
    in reply to tongyangn0002
    In this case I'd consider simply making the "save as draft" button skip validation altogether, such that the user can save a draft regardless of how many fields they've filled out, since your "submit to next person" button would ensure they've entered all required values before that stage anyway (since it sounds like that will come later).
  • That was what I did before with old requirement. But with the new requirement, I need to put some of rule input fields as required part when I click the "save as draft". I can not make some field as required only with skip validation.
  • Hello Tony,

    I like most of the suggestions from Mike and Robert which I have used in some complex requirements.

    But for me sounds like you can still achieve this with the validation Group but this "little detail" regarding the validationGroup which allows you to add multiple buttons to the form. Before trying all those restructures I strongly recommend you to try the following logic I modified your code which i think is for a version 16.x

    load(
      local!button1,
      local!button2,
      local!text1,
      local!text2,
      a!formLayout(
        firstColumnContents:{
          a!textfield(
            label: "text1",
            required: true,
            value: local!text1,
            saveInto: local!text1,
    		validationGroup:"button1" /*<<-- NOTE this*/
          )
        },
        secondColumnContents:{
          a!textfield(
            label: "texx2",
            required: true,
            value: local!text2,
            saveInto: local!text2,
            validationGroup:"button1 button2" /*<<-- NOTE this*/
          )
        },
        buttons: a!buttonlayout(
        primaryButton:{
            a!buttonWidegetSubmit(
              label: "button1",
              value: true,
              saveInto: local!button1,
              /*skipvalidation: true*/  /*<<-- NOTE this*/
    
              validationGroup:"button1" /*<<-- NOTE this*/
            ),
            a!buttonWidgetSubmit(
              label: "button2",
              value: false,
              saveInto: local!button2,
    
              validationGroup:"button2" /*<<-- NOTE this*/
            )
          }
        )
      )
    )

    I haven't found it documented for that reason I am not sure if it was deprecated or is beta or what happens. But so far it have solved  the form validations.

    Hope this helps

    Jose