PowerApps Exchange

Please login or click SIGN UP FOR FREE to create your PowerAppsUG account to join this user group.
Expand all | Collapse all

How can I keep a form from saving if the value in a required field is "0"?

  • 1.  How can I keep a form from saving if the value in a required field is "0"?

    Bronze Contributor
    Posted Jul 15, 2019 12:55 PM
    I have a form, customized from a SharePoint list.  Due to the inability to reset values on a numeric field to "blank" if anything has been entered and saved to that list, I had to set the form defaults to be "0."  But now, the form can be saved with a zero value - which is invalid.

    Is there any way to make this form error / not submit if the default value has not been changed?

    How can I say if any of 11 toggles are turned on, the form cannot be saved if the value in the related field is zero?

    I can obviously tell Power Apps to make the fields required if the value of the toggle is true, but it thinks "0" is a valid answer and will save the form...



    ------------------------------
    Carolee Heynen
    SharePoint & Office 365 Admin / Developer
    ------------------------------


  • 2.  RE: How can I keep a form from saving if the value in a required field is "0"?

    Silver Contributor
    Posted Jul 15, 2019 01:19 PM
    With 11 variables it may get a little complicated. I think you would have to put an if statement to set the mode of your Save/Submit button to test for "0" in the various items. It may be easier to set each line item so they have to answer the questions in order - Hide the items until the first item is answered without a "0" then change that edit mode to Disabled and reveal the next item. When they get to the bottom of this list you would only need to check the final item for a "0"

    ------------------------------
    Brian Scott
    Chief Creative Officer
    Concord NC
    ------------------------------



  • 3.  RE: How can I keep a form from saving if the value in a required field is "0"?

    Silver Contributor
    Posted Jul 16, 2019 04:44 AM
    Set the DisplayMode property on your submit button to be If(DataCardValuewhatever = 0, DisplayMode.Disabled, Edit)

    ------------------------------
    Will Page
    Technical consultant
    +64210436716
    ------------------------------



  • 4.  RE: How can I keep a form from saving if the value in a required field is "0"?

    Silver Contributor
    Posted Jul 16, 2019 06:03 PM
    Edited by Will Page Jul 16, 2019 06:18 PM
    In response to your private message...

    A solution to this, given it's a customised SharePoint form, is to set the behaviour of the OnSave action in the form to a formula that returns false if the condition isn't met.

    Click SharePointIntegration, then Advanced on the right, then More options to reveal the OnSave property. In this example I've made it so the value of a string field must be "Yes" otherwise the form won't save. There's no error message or tooltip or anything like that, the Save button is simply non-functional.

    You can adjust the formula for your needs. If it's a numeric column and it needs to be a positive number greater than 0 then use >0 in your If() statement. If you have multiple fields you want to be >0 then you could extend this If() with a lot of || (OR operations) or && (AND) operations.

    Another way you could do this is run the If() in the OnSave only on the last TextInput box as it appears on the form, and then set the DisplayMode property of each of the other ones to be dependant on the value of the one above it being > 0 - so the user can't change the next one from 0 and therefore unlock the Save button, unless all the previous default 0s have been changed.

    Lastly, add a big red bold label with a note saying "ALL FIELDS MUST CONTAIN A POSITIVE NUMBER OR YOU CAN"T SAVE THIS FORM" at the top and set it's Visible property or DisplayMode to a an If() statement with similar logic to the OnSave earlier, such that it disappears when all the fields are > 0 and the OnSave is working.

    If you wanted to get a bit more advanced, instead of the false value of your If() statement in the OnSave being false, you could use UpdateContext() to set a context variable to true, e.g. UpdateContext({context_badform:true}) then set the Visible property of a Label with an error message to context_badform and also set the OnChange property of all your input boxes to UpdateContext({context_badform:false}). This would pop up an error when someone tries to save the form with a 0 in, but then disappears when they change the value of any input box.
    ------------------------------
    Will Page
    Technical consultant
    +64210436716
    ------------------------------



  • 5.  RE: How can I keep a form from saving if the value in a required field is "0"?

    Bronze Contributor
    Posted Jul 16, 2019 06:23 PM
    You are a wizard!

    ------------------------------
    Carolee Heynen
    SharePoint & Office 365 Admin / Developer
    ------------------------------