Saxon-CE - recreating form controls and their current properties
Added by Ken Holman about 10 years ago
I am writing a web page where I am creating and destroying form fields based on user input into form fields on the same page (sometimes event the same field). Primarily the data types are checkboxes, though I suspect this is an issue I have for all field types.
Having created a checkbox, the user can set it or unset it, and I have access to the "checked" state of the event itself. No problem there.
Sometimes the act of setting a checkbox triggers my need to replace existing checkbox controls with new checkbox controls, and I can copy them just fine when I write to my result tree. Typically, it includes recreating the control I just clicked and replacing it as one of the many checkboxes I am recreating.
But I cannot find a way to preserve the checked status of the old checkboxes in the new checkboxes, and this makes sense since they are new controls and not the old ones, they are going to be created as being unchecked. So I need to, at the time of their dynamic creation, re-establish the checked property of the newly-created checkbox from the old one I am copying ... for each of them, one of which might be the one that was the trigger.
After many failed attempts I eventually settled on thinking that what would work should be as follows when handling the check of another particular box:
I also tried:
But this sets all of the newly created checkboxes to be the status of the result of the checkbox that was set by the event of clicking on the one checkbox that triggers the code. So the "@prop:checked" does not appear to be relative to the node I'm navigating to with XPath, it seems relative only to the last-matched node of the event.
I must be missing a fundamental concept from my reading of the documentation ... or, it just isn't possible to set user-interaction properties of controls when creating the controls in the HTML tree. But that would mean I simply couldn't ever create a checked checkbox, which I doubt is true, so it must be that I am missing something in the documentation.
Can anyone see the principle I'm not seeing myself?
Thank you for any guidance anyone can be.
. . . . . . . . Ken
Replies (1)
RE: Saxon-CE - recreating form controls and their current properties - Added by Ken Holman about 10 years ago
Okay, by creating an abbreviated test file, I think I have determined the principle I was missing: ixsl:set-attribute() appears to always work on the source tree and not on the result tree fragment that I am creating.
Though something isn't quite right in that simple statement, since I'm seeing an arbitrary value being set when accessing the property.
To try and explain, I've attached a short example that illustrates the issue: three controls, the first and last work fine in that their status is preserved until I press the second control to make a copy of all controls. At that point, all controls are checked regardless of their previous state and the copy has nothing checked.
The copy works fine in and of itself, it just doesn't start as a copy of the states of the source. And the states of the source get corrupted during the copy.
TestControlCopy.zip (1.65 KB) TestControlCopy.zip | HTML and XSLT of test |
Please register to reply