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

Parents
  • 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).
  • 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.
Reply Children
No Data