Re: [Xsltforms-support] Change instance via JavaScript?
Brought to you by:
alain-couthures
From: Alain C. <ala...@ag...> - 2011-11-14 21:20:37
|
Hello, The "javascript:" support in submission has been added in rev. 515 in the SF SVN repository. Here is a test case: <html xmlns:xforms="http://www.w3.org/2002/xforms"xmlns:txs="http://www.agencexml.com/txs"xmlns="http://www.w3.org/1999/xhtml"xmlns:ev="http://www.w3.org/2001/xml-events"xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <head> <title>Javascript Submission</title> <xforms:model> <xforms:instance> <data xmlns=""> <value>Initial value</value> </data> </xforms:instance> <xforms:submission method="get"serialization="none"replace="instance"targetref="value"resource="javascript:'<value xmlns="">Javascript value at '+(new Date())+'</value>'"/> </xforms:model> </head> <body> <xforms:output value="value"/> <xforms:submit> <xforms:label>Load from Javascript</xforms:label> </xforms:submit> </body> </html> As you can see, the resource is returning the serialization of the new instance. Thank you for your feedbacks! -Alain Le 11/11/2011 13:33, st...@sa... a écrit : > I am very inexperienced in XForms so I wonder if other XForms > processors provide a javascript: submission facility as well? > > If it would be a defined way of doing this kind of thing only in > XSLTForms I think it would still be interesting because although I > have solved my immediate problem, I can't help thinking it is a > bit of a hack. > > What I do now, in several different places in the UI, is this: > > Define both the target element and a dummy element in my > instance: > > <xforms:instance id="pager"> > <pager-session xmlns=""> > ... > <list>(none)</list> > ... > <dummy>dummy</dummy> > </pager-session> > </xforms:instance> > > Define a clickable button in my main form, and wrap it in a > dialog which is never shown: > > <xforms:dialog id="listChangerDialog"> > <xforms:trigger id="listChanger" name="listChanger"> > <xforms:action ev:event="DOMActivate"> > <xforms:setvalue ref="instance('pager')/list" > value="instance('pager')/dummy"/> > <xforms:send submission="post-pager"/> > </xforms:action> > </xforms:trigger> > </xforms:dialog> > > As you can see, I set the actual 'list' element value from a > 'dummy' element. > > Now, the Advanced Search popup is its own XForm. It runs the > search and leaves the results in a tmpdir which it needs to > pass back to the main window, the pager which allows the > user to page back and forward in the results. So, in the > popup XForm the instance is returned with a url: > > <url>javascript:oasNotify('pnveWbPgHo')</url> > > Which is loaded after the search completes: > > <xforms:submission action="/cgi-bin/oas" method="post" > id="post-search" > mediatype="application/xml" > replace="instance"> > <xforms:action ev:event="xforms-submit-done"> > <xforms:load> > <xforms:resource > value="instance('search')/result/url"/> > </xforms:load> > </xforms:action> > </xforms:submission> > > The JS function oasNotify is: > > function oasNotify(list) { > var model = window.opener.window.document.getElementById("pagerModel"); > var dummies = > model.getInstanceDocument("pager").getElementsByTagName("dummy"); > dummies[0].firstChild.nodeValue = list; > window.opener.window.document.getElementById("listChanger").click(); > } > > That is, it gets the pager instance from the main window (opener) > and sets the dummy value in it, then clicks the hidden trigger. > > That trigger (back to the top of this example) sets pager/list from > pager/dummy--and that is where I started this discussion: the sticking > point was that if you set pager/list directly, the refresh isn't > called so the instance submitted doesn't have the updated list > value. By using an explicit xforms:setvalue to set it indirectly > from pager/dummy, the refresh is triggered and the submitted list > value is the new one. > > I have no illusions about whether this will work with other > XForms processors--I'll just be happy if it doesn't break > suddenly on XSLTForms (which I love, incidentally). > > If I understand your suggestion, the new code would basically > cut out the copy from pager/dummy to pager/list because XSLTForms > would understand that a *submission* with javascript URL might > require a refresh, where it doesn't currently understand that > a *load* with a javascript URL might require one. I guess > it would still be necessary to have the hidden trigger to > send the post-pager submission (although I can imagine it > all being wrapped in one JS routine; I just don't know how to > do that offhand). > > If you need to see the context, you can launch the beta UI at: > > http://oracc.museum.upenn.edu/etcsri/launch/p2 > > Click on 'Advanced Search' and search for, say, 'lugal' > (Sumerian for "king"). > > That Advanced Search, btw Alain, includes the xforms:repeat inside > an HTML table stuff you helped me with when I first started playing > with this new UI last March--many thanks for that help, this help, > and XSLTForms! > > Steve > > Quoting Alain Couthures <ala...@ag...>: > >> Hello, >> >> Javascript URIs are not already supported in XSLTForms for submissions. >> >> I was just asking if it could be interesting because it shouldn't be >> difficult to implement and it would be quite elegant. >> >> What do you think? >> > > > |