Loading and saving text-data of a “plugined” textarea in eXist-db with HTML forms

╄→尐↘猪︶ㄣ 提交于 2020-06-17 10:06:53

问题


My original need was that of getting a plugin (tailwriter) to work with XForms (within eXist-db + XSLTForms), in order to transform textareas into markdown editors. It turned out, however, to be a hard issue to be solved, in reason of the "difficult relations" between the CSSs and JSs used by the plugin and by XSLTForms (overlapping and conflicts). In other words, I couldn't succeed in applying the plugin to any xf:textarea.

Therefore I opted for using a simple HTML form. This way I was able to apply tailwriter plugin to textareas (taking advantage of eXist templating system). The problem now consits in how exaclty loading and saving contents into and from textareas with respect to the xml file where they are saved. I succeed in calling the xquery module, but not in filling the saved xml file with the textarea's contents.

This is the html form:

<div data-template="templates:surround" data-template-with="templates/html-forms-page.html" data-template-at="insert:content">
<div id="sub_title">
    <hsb>Nota bene</hsb>
</div>
<div class="spacer_big"/>
<div class="spacer_big"/>
<div id="main">

    <form method="post" action="query_update_notabene.xq">
        <textarea id="textarea"/>
    <br/>

    <table border="0">
        <tr>                
           <td>
                <input type="submit" value="Salva nota"/>
            </td>
            <td style="width: 20px;"/>
           <td>
                <input type="reset"/>
            </td>
       </tr>
    </table>
    <br/>
    </form>
</div>

I then use the two following chunks of code inside my xquery, in order to save the textarea's contents, but I'm surely missing something, as both do not work (it seems I'm not able to pass the contents).

The first one:

let $nota_text := request:get-parameter("textarea","")
let $my_nota := <data>
                   <nota_text>{$nota_text}</nota_text>
                </data>  
let $store := xmldb:store($my_funcs:app_collection, "/prova_nota.xml", $my_nota)

And the alternative one:

let $text_to_insert := request:get-data()
let $store := xmldb:store($my_funcs:app_collection, "/prova_nota.xml", $text_to_insert)

Finally, if possible, I'd need also a hint on how to write the xquery for loading into the textarea previously saved text-data...

Many thanks

Alex

EDIT-1:

OK, at least I was able of solving the above last issue. Now I can load previously saved text-data from a node of the xml file, in the following way.

First of all I have modified the html form, in order to call an external xquery function from within it. Thus in substitution of:

<textarea id="textarea"/>

now I have:

<div data-template="my_funcs:md_textarea"/>

which calls the following function:

declare function my_funcs:md_textarea($node as node()*, $model as map(*)) as element(div) {
  let $arch_id := request:get-parameter("arch_id", "")
  let $tab_id := request:get-parameter("t_id", "")
  let $row_id := request:get-parameter('r_id', '')
  let $fold_id := request:get-parameter("f_id", "")
  let $my_content := xs:string(doc(concat($my_funcs:app_collection, '/', $my_funcs:my_archive))/archivi/archivio[@id=$arch_id]/cartella[@id=$fold_id]/tabella[@id=$tab_id]/tr[@r_id=$row_id]/nota/nota_text/text())
  return
      <textarea id="my_textarea">{$my_content}</textarea> };

The function, by requesting from the calling html form all the needed variables, extracts the text contents saved into the appropriate node of the data base xml file, finally putting them into the textarea.

Now I need only to implement the post method which has to pass to the saving xquery the new or edited texts. However, I'm not yet able of finding the right way for referencing the textarea value, in order to pass its contents to the saving xquery...

EDIT-2:

I have extracted this last issue as a stand-alone question, because the specific problem can rise to a more general one: see related question

来源:https://stackoverflow.com/questions/61998919/loading-and-saving-text-data-of-a-plugined-textarea-in-exist-db-with-html-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!