cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper II
Helper II

Approach for clearing editform fields on change of another field (CDS data source)

Hello all,

 

I've got an/several edit forms connected to a CDS data source.

Here's a scenario:

I've got a yes/no field, a combobox and a text field.

 

Outcome:

when i mark the yes/no field to no, i need to clear the combobox and text field. the submit form action should then push this to CDS.

 

I know there is an option about using a variable, but i don't know if that will scale across 100s of fields?

thoughts?

10 REPLIES 10
Highlighted
Super User III
Super User III

Re: Approach for clearing editform fields on change of another field (CDS data source)

I got you right then, Put this on the SubmitButton: clear(ComboboxName); Clear(TextBoxName)

Highlighted
Helper II
Helper II

Re: Approach for clearing editform fields on change of another field (CDS data source)

@eka24 

The Clear function expects a collection parameter so i get an error 😞

Also i should have clarified - since i'm doing this within an edit form, i need to clear the datacardvalue.

I have attacched a screenshot.

 

Ideally, i would like to use something like a clear function on the uncheck action of the toggle.

Thoughts?

Highlighted
Super User III
Super User III

Re: Approach for clearing editform fields on change of another field (CDS data source)

Please watch this short video on resetting controls
https://youtu.be/PxUKma-zzPI

For the Toggle: Reset(ToggleName)
Also: Reset(Combobox)
Highlighted
Super User
Super User

Re: Approach for clearing editform fields on change of another field (CDS data source)

If the fields are in a form then MOST of the time just making sure you have ResetForm();EditForm() on whatever you click to start the form will reset the fields. 

 

If the default in the card was a text input for example and you changed it to a radio button then you will have to add additional steps to reset it. On normally put on the screens OnVisible=UpdateContext({ResetRB:!ResetRB}) and then on the radio button the reset value is ResetRB. You can do a similar approach for checkboxes, comboboxes, etc. 

 

But any that are a default field to the card in your form should not need any extra step other than the ResetForm() mentioned above to reset the previous data. 

Highlighted
Helper II
Helper II

Re: Approach for clearing editform fields on change of another field (CDS data source)

Thanks for your responses both. I should have been a bit clearer with what i was looking to achieve:

When i mark a toggle to no, I want to clear/blank/empty out the data in related fields i.e. set them to empty.

 

I've tried using the reset function that fires when a toggle is unchecked, but that only resets the value to the last value from cds. It doesn't clear the value.

Any pointers would really be appreciated

@rebeccas @eka24 

Highlighted
Super User
Super User

Re: Approach for clearing editform fields on change of another field (CDS data source)

A Reset() ...whichever route you choose is going to reset it back to whatever you have the default value to. If you want it to be blank when it is resets then you will need to change the default of the input field to "".

 

It is probably currently ThisItem.FieldName...just change it to "" and then it will go to blank when it is reset. This will work if you are doing new entries..not on edit though.

Highlighted
Super User III
Super User III

Re: Approach for clearing editform fields on change of another field (CDS data source)

An Editform always picks the records from the table for editing purposes unless the field in the table is blank.
You try:
If(YourEditForm1.Mode=FormMode.Edit," ",Parent.Default)

Highlighted
Helper II
Helper II

Re: Approach for clearing editform fields on change of another field (CDS data source)

I managed to figure out a fairly good approach (i hope):

For the field(s) that are dependent on the toggle, i use the following formula on the data card value control default property:

If(toggle.Value,Parent.Default,Blank())

 

Although, this has raised a separate question around approach. Since i am doing this in a form I have the option of using this formula at the datacard level or at the datacardvalue level.

For the datacard i use (on the default property):

If(toggle.Value ,ThisItem.'Field Name',Blank())

For the datacardvalue i use (on the default property or defaultSelectedItems property)

If(toggle.Value,Parent.Default,Blank())

 

Any thoughts on if one is better than the other?

Highlighted
Super User
Super User

Re: Approach for clearing editform fields on change of another field (CDS data source)

I don't think you need it on both the datacardvalue and the datacard. If you just have the datacard look to the datacardvalue then you can just set the datacardvalue to the :

 

If(toggle.Value, ThisItem.'Field Name',Blank())

 

You would just then make the default of the datacard nothing...just clear it out or leave it with the default. It won't matter because you are overwriting it in the datacardvalue part. Leave the Update part though. 

 

I use a similar approach on one I have. It is looking the value of a column in my data source and if it is a certain value then it puts that value in my field showing, otherwise it is blank and they are required to fill it in.

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Watch Now

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (7,381)