Hi Team,
I am using a Scanner in my app. The code written in OnScan property runs and keeps it states while we are in the app.
However, I am looking for any way if the OnScan property state can be reset for each item in the gallery.
The thing happening here is when I select an item of gallery, the last state/ scanned value remains same.
Is there any way we can refresh the state of OnScan property and get the code rerun for each item of gallery?
Appreciate any help on this!!
Solved! Go to Solution.
One key point in my last reply : " (and I say that because IF this is in a Gallery, then the approach is different)"
So...as I gather your logic. A user can enter a value in the weight and then press confirm. You then want to "lock" the input to view mode, so there is no way to have the user enter anything else once they press confirm.
IF that is a complete and true statement, then the following will work:
(The below is predicated on your items in the Gallery having a unique ID.)
- For the Confirm Button OnSelect action:
UpdateContext({lclConfirms: lclConfirms & ";" & Text(ThisItem.ID) & ";"})
- For the DisplayMode of the TextInput2
If(";" & Text(ThisItem.ID) & ";" in lclConfirms, Disabled, Edit)
- For the DisplayMode of the Button:
TextInput2.DisplayMode
What the above does is just concatenate a text variable with the unique ID of the list item. Then the other controls base their mode on the presence or lack of that ID in the text string. The semicolons around all the ID values is just to make sure that the find of that ID in the text is exact.
The OnScan is an action of the control, not a property. So you can utilize the Reset property of the Scanner control to reset the scanner in order for it to release its prior values.
I could provide a few options on how to best do that, but I am not sure how you are designing your app and how the scanner control is set up in your app. If you need more guidance on resetting the control, provide some details on your app design.
I hope this is helpful for you.
Hi @RandyHayes ,
Sure. My app screen looks like below :
and in my On Scan property, I am changing the Scanner text name from Scan T to Scan P. But what's happening currently here is when I select an item of gallery at first the Scanner name is 'Scan T' and as soon as I scan one barcode it changes to 'Scan P'. But in case if user doesn't scan the second barcode it still remains to 'Scan P' that's fine but when I go back and choose another item from the gallery it's on 'Scan P'. However, I need it to reset the scanner and should appear as 'Scan T' which comes up while starting the app.
Hope it make sense.
Let me know if you would like check on OnScan code as well, if that will make it more clear.
A couple of things I am not following:
- Where is the Gallery in this picture? How are you "choosing another item from the gallery"?
- What is the OnScan action formula that you have now where you have this logic for Scan T or P?
Hi @RandyHayes ,
Thanks for your quick turnaround. Ah I see there is only one item in this gallery as this is what I see in web browser. But there are list of items in the gallery.
And the formula for Scan T and Scan P is written in OnScan property of the scanner.
However, nevermind.. I got a workaround by adding the formula on back button of this gallery screen.
Set(gvscanname, "Scan T");
and it appears to start the scanning fresh for each item in gallery.
Yes, I was driving at the potential that you had some variable you were setting and clearing that out. Sound like you have worked around the issue.
Hi @RandyHayes ,
In addition to that, can I ask one more thing..
I am looking for disabling the text input after user confirms the weight.
If(Weight_ErrorMessage.Visible = false,TextInput2.DisplayMode = DisplayMode.View)
I have written above code in OnSelect property of 'Confirm Weight' but it doesn't appear to be working.
Could you please suggest how can we achieve that?
Really appreciate all your help!!
You cannot set a control property in PowerApps much like you cannot set a cell in Excel to be a value from other cell.
You need to reference in PowerApps (again like Excel - as PowerApps was modeled around Excel).
So, your DisplayMode property of the TextInput2 control should be:
If(Weight_ErrorMessage.Visible, Edit, View)
Now...this will also depend on the visibility of the label. If you have set the Visible property to something like :
IsBlank(Weight_ErrorMessage.Text)
Then this will create pain for your users because as soon as they type something into the textinput. The label will go away and the text input will shift to view.
So in this case, you need to move your value-chain further a step, and into a snapshot variable.
So, the formula on your button OnSelect action would need to take a snapshot of the value in the TextInput and then everything would be based on that (that's what I mean by moving the value-chain further).
So at its basics (and I say that because IF this is in a Gallery, then the approach is different), your formula on the OnSelect action would be:
Set(weightValue, TextInput2.Text)
Then the Visible property of the label would be : IsBlank(weightValue)
The DisplayMode property of TextInput2 would be : If(IsBlank(weightValue), Edit, View)
This would give you that basic capability.
Hi @RandyHayes ,
Thanks for the detailed information. It really helped.
However, when I m trying below on the confirm weight button in the Gallery, it changes the display mode for all TextInput to View whereas I just need for that particular item.
Set(weightValue, TextInput2.Text)
Then the Visible property of the label would be : IsBlank(weightValue)
The DisplayMode property of TextInput2 would be : If(IsBlank(weightValue), Edit, View)
I tried referring it with ThisItem but can't figure out where to put.
One key point in my last reply : " (and I say that because IF this is in a Gallery, then the approach is different)"
So...as I gather your logic. A user can enter a value in the weight and then press confirm. You then want to "lock" the input to view mode, so there is no way to have the user enter anything else once they press confirm.
IF that is a complete and true statement, then the following will work:
(The below is predicated on your items in the Gallery having a unique ID.)
- For the Confirm Button OnSelect action:
UpdateContext({lclConfirms: lclConfirms & ";" & Text(ThisItem.ID) & ";"})
- For the DisplayMode of the TextInput2
If(";" & Text(ThisItem.ID) & ";" in lclConfirms, Disabled, Edit)
- For the DisplayMode of the Button:
TextInput2.DisplayMode
What the above does is just concatenate a text variable with the unique ID of the list item. Then the other controls base their mode on the presence or lack of that ID in the text string. The semicolons around all the ID values is just to make sure that the find of that ID in the text is exact.
User | Count |
---|---|
124 | |
87 | |
86 | |
75 | |
69 |
User | Count |
---|---|
214 | |
181 | |
140 | |
96 | |
83 |