if that value matches the one in the row the checkbox will be checked.
(it then sends an update action to the server)
desired effect:
I know I could do a similar thing with a server action but I’d rather avoid constant data source refresh.
With a simple javascript I am able to get the index of the row with the matching value but I’m stuck on that as I don’t know how to reference that particular row (flow doesn’t seem to have an action like that).
Ok, so after playing around and reading various posts I found out about “dmx-bind:id=”. With it I could just give each checkbox a unique id (dmx-bind:id="‘checkbox’+$index") and check it with a simple script.
I’m still curious if it’s possible to do with wappler tools…
Also, something I found out is that “Value Changed” dynamic event doesn’t register when it’s javscript checking the box. I have it bound to auto submit form and it only works when it’s clicked by user.
“Value Updated” registers everything though - including “Checked” dynamic attribute that first updates the checkboxes when the table loads - thus basically sending another update action for each checked box… I guess it’s not ideal but it’s not a big deal.
here’s what happens when I load a table with some checked fields and “Value Updated” dynamic event set to submit form.
I’m not quite sure what needs to happen, but for a checkbox to be selected if its ID matches the value entered into an input value, you can use: dmx-bind:checked="(id == input.value)"
But then it wouldn’t show up as checked if the datasource had “1” in that field…
What I want it to do is when you input a string say “LPNHE432114545” it’ll find the row that has it and then check the checkbox (which will in turn send a server update action).
It will be used to confirm delivery of various products on pallets. The input will be made with a barcode scanner.
I'm not sure what you mean. If the input value - entered via a keyboard or barcode scanner - equals the ID of the checkbox (using dmx-bind:value="id" ), then the checkbox will be selected. I thought you didn't want to use a server action, but if you do, you could trigger a server action when the ID is entered. This wouldn't cause a page refresh.
and I'm already using that bind so when you first load the data you can see what already has a "found" status.
The other thing you said though - binding a more meaningful value to id is a great idea and could be a nice shortcut.
Thanks for your input!
if you want you can check out the project at http://test.luxray.pl/zebra.html
just put 13910498 in the first box and any of the LPN strings you see below in the other one.
I assumed you were using a separate server action to populate the page on load. I'm still not quite sure what you mean, but in case it's useful, I think you could use both the input and database values for the checkbox, eg: dmx-bind:checked="((id == input.value) || (id == 1))"
I wouldn't exactly describe this as a 'caveat'. It would be surprising if the behaviour were any different. The checkbox is only checked because the matching value is entered; if the value is removed, the checkbox will be be unchecked. You mentioned you would run a server update action after the value was entered - this would solve the problem.
Yeah I knew that would happen with a condition like that but I hoped that triggering a server action would perhaps keep the checkbox checked but for it to work like that I’d need to reload the data (which I wanted to avoid).
So I ended up doing it a little differently but I think I’m satisfied with it.
Maybe I should’ve mentioned that I need to be able to update that field in two ways:
by entering that LPN string in the text input
by just manually checking it
for number 2. I have a form in the table row that has a hidden id field and that checkbox with a dmx-on:changed="form2.submit() event. Easy.
number 1. was more tricky because dmx-on:changed="form2.submit() doesn’t trigger if you check a checkbox using a script or dmx-bind:checked="(id == input.value)". dmx-on:updated="" does, but it also triggered every time you load data (that already has some of those checkboxes checked).
I made another hidden form but one that doesn’t repeat like the one in the table. I used dmx-bind:id="LPN" with the checkbox so I can get to it with a script and check it (those LPN values are all unique and I can just use that value from the text input). Then I grab the id of that record from another field, parse it into form’s hidden input and submit.
I wish you could target a specific repeat child with Flow - then I could just submit the form from there. Also if dmx-on:changed triggered when checking a box via script…
Anyways, time for some well deserved Disco Elysium fix
Given you want the checkbox to remain checked after the matching ID is no longer entered in the input, it makes sense to trigger the update (though there are probably other ways to do this). In this case, you will need to reload the data. Why do you want to avoid this? The page won't refresh - the update is made using Ajax. I use a lot of checkboxes in tables; I don't think there would be any apparent difference to the user whether they are simply checking the checkbox, or checking it and doing an update.
Again, I'm not quite sure what you mean, but you can pass parameters to flows from repeats, so I would have thought you could do what you need, with or without a flow.
I'm not sure what that it, but it doesn't sound liquid enough.
It'll have to run on a little Android PDA bar-code scanner and those things have the computing power of a large potato so having it reload all the records for every scanned item might be an overkill
Yeah but only if that particular repeat or row in a table triggers that action and not when it's triggered somewhere outside of that repeat, as far as I could see.
Ah - I wasn’t taking any potato-related issues into account. You could put the IDs into a variable or hidden input etc. and update a batch of records to avoid multiple database queries. But there are probably lots of solutions, and it seems you’ve found one that will work which is the main thing.