in browser/search.pt we have: <input type="text" size="60" name="decree-fulltext" id="decree-fulltext" tal:attributes="value request/decree-fulltext|nothing" />
in browser/search.py we perform the search, but before that we need to remove 'un-searchable' characters from field ''decree-fulltext' and send back to this form field in next search.
in browser/search.py we tried:
search_able_text = .....
self.request['decree-fulltext'] = search_able_text
self.request.form['decree-fulltext'] = search_able_text
but it does not work.
Please give a hint.
Many thanks for your times.
What part does not work? From your emphasis, I assume that the search was correct but the form did not get the changed value for the next search. Did this happen?
Then, it would not surprise me: forms usually have (at least) 2 exits: an error exit which returns to the form itself with values from the request (to allow the user to fix any problems) and a normal (action) exit which goes somewhere else. In the second case, when you come back to the form, likely a new request is active which does not know anything about your corrections.
You should also tell us whether this is a standard Plone form (which Plone version?) or a custom form: Plone uses form frameworks for many of its forms (e.g. zope.formlib, CMFFormController, z3c.form) and those tend to add prefixes to field names. The request contains those extended field names.
To include code in your posts, try indenting it by four spaces or use the </> icon in the editing toolbar after selecting the code (that’s what I did to edit your code line that starts with form)
hi @tkimnguyen
the same user in the same browser tries to search
love apple
the user will get result of search "love apple" (withou ) and the same form above search reasult with the field id="decree-fulltext", but the value of this field is still the same:
love apple
because in browser/search.pt this "decree-fulltext" field has been set: <input type="text" size="60" name="decree-fulltext" id="decree-fulltext" tal:attributes="value request/decree-fulltext|nothing" />
we need to set the value of field only to "love apple", e.g. the new value of field id="decree-fulltext" must be escaped from 'unsearch-able' character
Obviously, this is a custom form -- and one with a surprising implementation. Can you share the code behind context/absolute_url. It is this code which is responsible to do the searching and redisplay the search form with the updated form value.Show us how you change the value, perform the search and reactivate the template.
I think you are looking/asking for some 'two way binding' system, where the server can update fields on the client, like you can do with meteor and other frontend systems. This is not in place in default Plone, you'd have to develop it yourself with loading extra javascript code in the frontend.
With the forms framework used (z3c.form) there is per field server side validation possible, validator configured in on a field in the form schema are run, but AFAIK it doesn't support suggesting a new field value, only returning valid or invalid with an error message.
What if you add a javascript to browser.pt and set the text of the input field with javascript,
Maybe return the (whole) javascript from search.py or just the "input text"
PS
<script>myscript here ${view/get_variable} more script here</script>
should also work