web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / set a Text input manda...
Power Apps
Unanswered

set a Text input mandatory

(0) ShareShare
ReportReport
Posted on by 110

Hello all,
I am trying to make a text input field mandatory only if a toggle is enabled.
If the text input field is blank, i would like to display a message or highlight the field in red when i submit the form.


My toggle: DatacardValue42.Value
Text input field: DataCardValue39.Text

Thanks beforehand.

Categories:
I have the same question (0)
  • RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @AOZ 

    Set the Required property of the DataCard that contains DataCardValue39 to : DataCardValue42.Value

    This will then cause the field to be required when the toggle is on.

     

    I hope this is helpful for you.

  • AOZ Profile Picture
    110 on at

    Hi @RandyHayes 

    Thanks for your help.

    I have the following items in the datacard.

    The first is becomes visible and filled with the order number and the section text.

    The second is the comment box which we want to render mandatory if the toggle is active (even if there is no photo taken)...

    I tried your steps...it still allows me to save (i suppose that it is seeing that the first box is filled)...

     

     

    AOZ_0-1619446247364.png

     

  • RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @AOZ 

    You should avoid using multiple controls in a datacard that go with different fields in your list.  You should have a datacard for each field.

    The Required property of the form will indicate to the form that it should reference the Value produced by the Update property of the DataCard.  If it is blank, then the form will produce a "required" message at the point that you issue a SubmitForm on the form.

     

    So...if the Update property produces a value and Required is true, then the form will consider it filled in and valid.

    You will need to look to see what value your Update property is producing.

  • AOZ Profile Picture
    110 on at

    @RandyHayes 

    I was thinking about something like below when the submit form button is clicked. 

    If(!IsBlank(DataCardValue39.Text),SubmitForm(EditForm1);

     

  • RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @AOZ 

    You could do that, but the preferred method would be to:

    1) Disabled the submit button if the form is not valid

    2) Provide some "message" to the user where the data is required so they know immediately.

     

    The Form has a Valid property that can be used to determine if it is valid.  The formula for Valid is - If the datacard is required (Required: true), does the Update property produce a value.  If no value, then the entire form is not valid (Valid = false).

     

    SO...yes, you can base your validity off of one specific set of conditions, but it gets a little confusing to maintain if you have more than just the one and the Form datacard Required and Update properties are the better choice to determine validity.

     

  • AOZ Profile Picture
    110 on at

    @RandyHayes 

    I am finally opting for this option.

    I now just need like a display of an error message and preventing the form from displaying a blank page and losing all entries already entered.

     

    AOZ_0-1619460888532.png

     

  • RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @AOZ 

    I am not sure what the option is that you are opting for.   It looks like you might be just doing a full submit to the datasource and letting it error out.  

    In general, not such a good idea as you want your data to be validated prior to submit so that you're not wasting a round trip through the cloud.

     

  • AOZ Profile Picture
    110 on at

    @RandyHayes 

    I am using your advice. i.e making the comments field a Datacard containing only 1 field and linked to the list.

     

    "Set the Required property of the DataCard that contains DataCardValue39 to : DataCardValue42.Value

    This will then cause the field to be required when the toggle is on."

     

    In my submit button, there is only the following code:

    SubmitForm(EditForm1);

     

    Can you help to validate the control first before submitting?

     Any error display is OK before submitting...

  • Verified answer
    RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @AOZ 

    So I would also consider then setting the DisplayMode on the button to:  If(yourForm.Valid, Edit, Disabled)

    If you want to do something more "fancy" for the users, then you can also do something like this, In the OnSelect of the button:  

    If(yourForm.Valid, 
     SubmitForm(yourForm);
     UpdateContext({showErrors:false})
     ,
     UpdateContext({showErrors:true})
    )

    Then, but labels in your Datacards to display an error message (you can refactor the ErrorMessage labels already there).  Set the Visible property of the label to : !Parent.Valid && showErrors

     

    This will allow the user to click the button once and then they will see any errors you might want to display if the datacard is not valid.  The form will not submit until the form is valid.

     

  • AOZ Profile Picture
    110 on at

    @RandyHayes 

    Thanks! This works out perfectly fine!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard