Iād like my input fields to serve as both display field and input field. Iāve seen many websites doing that.
Right now Iām cheating by using the placeholder value for displaying data and the value binding field for updating data, but thatās no best practice.
Any better suggestion from the masters of AG?
Donāt know if this helps, but I created a single form, and I just create a page variable for the record ID. If I click on an existing record, I set the ID and this tells me I am editing the record (or perhaps deleting). Otherwise, I know I am adding a record.
Thanks Daniel,
I guess Iām too new to understand how to implement it but I see where you are coming from.
This is my working ācheatā setup where I use the placeholder area to retrieve the data from the resource and i use Value to make updates to the data:
When I hit the button, how to I fetch the updated data in the input field which is bound to a GET data variable? How do I make the switch between this var and some var that will hold the data to be updated in the resource?
I think Iāve made some progress.
The value of the input field is bound to a pageVars whose schema is the same as that of the data variable that retrieves data from the resource.
On page focus, I set the page variable to the values of data.getProvider:
Your latest approach is almost correct - whatās happening is that the page focus event happens and the values are bound before the data is fetched. The solution is to set this logic in the variables tab, editing the logic of the single-type data variable (or whichever youāre using). Populate your page variable after the get record flow and it should work. Do note that youāll have to disconnect the loop that refreshes the data every 5 seconds or your input fields will constantly reset back. In this case, youāll have to set up some custom event to refresh the data when you update the record.
Alternatively, you can make a true/false page variable, letās call it āupdateDataā, and use an IF flow function after the get record flow to check if said variable is true. If it is, update your local data, and make the updateData variable false. Then, you can set up the update button to make the updateData variable true, allowing the data to refresh again.
Hopefully that was understandable. Let me know if it worked out for you!
Indeed, Iāve figured that out last night and addressed it simply with a 500ms delay between page focus and the set pageVar.
Now my struggle is that I can no longer update the data.
It used to work well when the input field value was bound to the data var that updates the resource with SET_KEY(data.getProvider, "corpName", data.updProvider.corpName) in the update record function.
Now the field value is bound to the pageVars that āfetchesā data from data var.
On tap, I set the āupdateā data var to the input value of pageVars:
Using just a delay can be a bit wonky- if the connection is poor, fetching the data might take longer than 500ms, which is why I recommend setting the variable after the get data flow is complete.
To help you with the updating issue, Iād need some additional info: After updating the record, do you use the get record flow to get the latest update? Or does your database return the updated item after an update? By ānothing happensā, does the update record fail (go into the second output) or just not do anything? Does your app has write permissions to the database? Is there a reason you canāt use the SET_KEY formula anymore? i.e. SET_KEY(data.getProvider, "corpName", pageVars.updProvider.corpName)
I donāt get the latest record, no need because the last typed in update in the field remains displayed there in the field after save. I want it to be updated in the database.
No fail, just the button click does nothing. Write/Read permissions same as before, all open.
What if I set the data var after the input field component onChange event?
Thanks for your intervention.
Debug did not provide any message because it was something else which I fixed. I had an onBlur event that hides the button when input field no longer focused.
Iāll share a little tutorial about this two-way input field feature for all newbies like me.
The page might be crashing due to either the āfalse until data=trueā being setup incorrectly (i.e. it never gets set to true) or because the logic in this loop is being executed constantly with no delays. You can also try attaching this logic directly to the data variable logic canvas instead of the page focused event.
I went for this solution, because I do not see where the BOOLEAN and/or the IF setups could be wrong. Thanks so much!
Are you now the person in charge of assisting the community here?