cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Submitform resets toggles

Hello,

 

I have an EditForm that holds several data cards connected to a datasource (Dropbox table). Each datacard has a toggle. Once the toggle is checked a text input box becomes visible. When I check the toggles, input text and then press 'save' (Submitform), the toggles reset to 'off' mode, meaning that the text becomes invisibile again.  How can I stop the toggles resetting after I submit the form?

 

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions

You can use a Patch instead of submit for the form:

Patch(DataSourceName, Record, EditForm1.Updates)

But that still won't solve your problem if the toggle is inside the form (when the item is updated, the Item property of the form will be re-evaluated, causing the controls to be reset.

 

You can have the controls outside of a form (i.e., in the canvas directly), and use the Patch function as you would like - you'd just need to specify all the updates individually instead of relying on the form to collect them for you. In your case, it would be something like

Patch(
    DataSourceName,
    Record,
    {
        proteinDateCompleted: TotalProteinDateCompleted.Text,
        aminoAcidsDateCompleted: AminoAcidsDateCompleted.Text,
        ...
    })

Where 'proteinDateCompleted', 'aminoAcidsDateCompleted' are the names of the columns in your data source, and 'TotalProteinDateCompleted', 'AminoAcidsDateCompleted' are the name of the controls from where you're getting the values to update.

 

Your hacky solution wouldn't work - you want the toggle property to depend on the visibility of the TotalProteinDateCompleted control, but the visibility of that control depends on the toggle value. That creates a cycle that should be indicated as an error if you try to do that. The language of PowerApps is in many ways similar to a functional language - properties are defined as functions of other values, and if you have a property A defined as a function of B, and B defined as a function of A, that is inconsistent and is not allowed.

 

Another option you can consider is to store the visibility state of the toggles in your data source itself. For example, in addition to the column to store the date the total protein analysis was completed, you can have another property that indicates that the analysis has started (in which case you want to display the text input, with a possible blank value). Then you'd bind the default property of the toggle to that new column.

View solution in original post

8 REPLIES 8
Anonymous
Not applicable

Hi @Anonymous

 

The toggles might reset for few reasons. Do you call ResetForm() anywhere? What are the default form mode? What are the Default property of each toggle? How do users navigate to the form? What is the function for text to be visible?

 

Can you share some screenshot as pictures is worth a thousand words when solving issues.

 

Anonymous
Not applicable

Hi @Anonymous, thank you for the reply.

 

In answer to your questions:

  • I do not (knowingly) call `ResetForm()` anywhere. I have scoured the app for this function but can't find it.
  • The form's default mode was 'new', I then changed it to `edit` but this didn't help.
  • The default property of the toggles is `false`. (Could this be the problem?)
  • The form is navigated to via an icon on the `BrowseScreen` with the function `Navigate(EditScreen1, ScreenTransition.None)`.
  • The function for the text to be visible is `If(Toggle1.Value = true, true)`.

It is worth noting that the text does not reset after using `SubmitForm()`, it is only toggles and check boxes that reset. This causes the text to become invisible, but the new text is still there when you check the toggles again.Deleteme.png

Whenever you submit a form, then all the controls are reset to their default values - and since the default value for the toggle is false, it will be unselected when you submit. This is the behavior of the form because there are many cases when after a submission is done, the data is changed in the server side (one example would be a SQL server trigger), so the form needs to display the most up-to-date information after the submission.

 

In your case you only have the toggle turned on when you have (or are adding) a value for the "date completed" field, correct? If this is the case, then you can set the toggle's default value to reflect that. Something along the lines of this expression for the Default property of the toggle:

 

!IsBlank(TotalProteinDateCompleted.Text) And !IsEmpty(TotalProteinDateCompleted.Text)
Anonymous
Not applicable

@CarlosFigueirathank you so much for this reply.

This is a great answer and very close to what I want. However, my idea was to check the toggles if that analysis was required (e.g. protein) and then enter the text in the date completed input box when the analysis was complete. So I would still like the toggles to remain checked even if the text boxes are empty (an example may be when one analysis has been completed but another has not).

Would a hacky option be to make the default property of the toggle something along the lines of:

IsVisible(TotalProteinDateCompleted.Text)

?

 

Sorry, I am not new to coding, just to Powerapps.

 

Otherwise, given the innate characteristics of the SubmitForm() function you described, do you think I may be better off using the Patch() function? I have tried this but have trouble figuring out what the formula should look like to submit a whole form.

 

Thank you

You can use a Patch instead of submit for the form:

Patch(DataSourceName, Record, EditForm1.Updates)

But that still won't solve your problem if the toggle is inside the form (when the item is updated, the Item property of the form will be re-evaluated, causing the controls to be reset.

 

You can have the controls outside of a form (i.e., in the canvas directly), and use the Patch function as you would like - you'd just need to specify all the updates individually instead of relying on the form to collect them for you. In your case, it would be something like

Patch(
    DataSourceName,
    Record,
    {
        proteinDateCompleted: TotalProteinDateCompleted.Text,
        aminoAcidsDateCompleted: AminoAcidsDateCompleted.Text,
        ...
    })

Where 'proteinDateCompleted', 'aminoAcidsDateCompleted' are the names of the columns in your data source, and 'TotalProteinDateCompleted', 'AminoAcidsDateCompleted' are the name of the controls from where you're getting the values to update.

 

Your hacky solution wouldn't work - you want the toggle property to depend on the visibility of the TotalProteinDateCompleted control, but the visibility of that control depends on the toggle value. That creates a cycle that should be indicated as an error if you try to do that. The language of PowerApps is in many ways similar to a functional language - properties are defined as functions of other values, and if you have a property A defined as a function of B, and B defined as a function of A, that is inconsistent and is not allowed.

 

Another option you can consider is to store the visibility state of the toggles in your data source itself. For example, in addition to the column to store the date the total protein analysis was completed, you can have another property that indicates that the analysis has started (in which case you want to display the text input, with a possible blank value). Then you'd bind the default property of the toggle to that new column.

View solution in original post

Anonymous
Not applicable

@CarlosFigueirayes yes yes!

 

Your last idea of creating new columns in the datasource and binding the toggles to these works and is actually a smarter solution for my requirements. I am just wondering how I can do the reverse, so if I check a toggle in the app, how can I make this add text to the datasource cell (and therefore remain checked)? It can just be any text (e.g. "x") since your code just requires the cell to not be blank.

 

Thank you so much

If you have a column in the data source that identifies whether the value should appear (e.g., totalProteinAnalysisStarted), then you can go back to using forms - that should be easier than using the Patch manually (although using Patch isn't that much harder). In this case you would have another card in the form that would be bound to that new column. If you add it via the form customization pane, it will automatically set its default value to match the value of that column in the data source (assuming that the column is defined with type boolean / logic / yes/no / bit - depends on the data source).

 

If the type of the column is different (such as text), then you'd set the default property to an expression. For example, if you store an "X" if the toggle had previously been turned on (e.g., the total protein analysis has started), then the 'Default' property in the toggle would be set to totalProteinAnalysisStarted = "X".

 

 

If you want to go to the non-form route (which gives you greater flexibility over the design of the screen), then you can set the Default property of the toggle controls to the value to the property of the object being edited directly (if the type is boolean) or to an expression that returns a true/false value, like the example in the previous paragraph

Anonymous
Not applicable

@CarlosFigueiraafter much confusion and frustration, I found that your earlier suggestion of inserting the toggles directly onto the canvas (i.e. no form) and using the patch() function to save the changes to the datasource was the answer! I have accepted it as the solution.

Thank you sooooo much 🙂 🙂 🙂

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Users online (1,000)