Change form field value

in browser/ we have:
<input type="text" size="60" name="decree-fulltext" id="decree-fulltext" tal:attributes="value request/decree-fulltext|nothing" />

in browser/ 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/ 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.

thanks @dieter

if user enter to field

id="decree-fulltext" tal:attributes="value request/decree-fulltext|nothing"
love :diamonds: apple

we will find text
love apple
and will send back the search reasult, plus we want to set new value of field "decree-fulltext" to "love apple"

So the search part is working perfectly, but we dont know how to set new value to field "decree-fulltext" in new search

in browser/ the form has such action:

form method="post" tal:attributes="action context/absolute_url">

our Plone is version 4.3, from debug i see it use Products.PloneFormGen-1.7.11-py2.7.egg
the class for searching is extended from BrowserView.

Many thanks.

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)

It’s not clear who performs the next search or when the next search takes place.

Do you mean that:

  1. Someone uses the form to perform a search
  2. The search is performed using the cleaned up search string that was entered by the user
  3. At this point the search form is still shown in the browser but with the cleaned up search string instead of the original search string?

hi @tkimnguyen
the same user in the same browser tries to search
love :diamonds: apple
the user will get result of search "love apple" (withou :diamonds:) and the same form above search reasult with the field id="decree-fulltext", but the value of this field is still the same:
love :diamonds: apple

because in browser/ 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

Is this 'live search', a portlet, or after you get redirected (by normal search) to

If it is live search, I assume you need to modify the live search javascript to change content of the input field

ok, better to describe the problem by ... pictures :slight_smile:

first the user enter text to search:
dle ░ přílohy
he gets the results of searching "dle přílohy" only , with the form above search result

we need to remove ░ from the form from the result step.

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.

@espenmn thank you, i think it is portlet

@dieter thx for your time,
here is code of browser/

<html ....xmlns...>
<metal:content-core fill-slot="content-core">
    <metal:content-core define-macro="content-core"
        tal:define="mtool nocall:context/portal_membership;
                    toLocalizedTime nocall:context/@@plone/toLocalizedTime;
                    editor python:mtool.checkPermission('Modify portal content', context);
                    text context/getText;">
        <tal:span tal:replace="structure text">Body</tal:span>
        <form method="post" tal:attributes="action context/absolute_url">
            <table id="rzmo-search">
                    <input type="checkbox" value="search" name="decree-board" id="decree-board" tal:attributes="checked request/decree-board | string:checked" />
                         <label for="decree-board" i18n:translate="">City board</label>
                    <input type="checkbox" value="search" name="decree-council" id="decree-council" tal:attributes="checked request/decree-council | string:checked" />
                        <label for="decree-council" i18n:translate="">City council</label>                                          
                    <label for="decree-period" i18n:translate="">Election periods</label>
                    <select size="1" name="decree-period" id="decree-period" tal:define="selectedItem request/decree-period|nothing">
                      <option tal:repeat="item view/getPeriods"
                              tal:attributes="value item/shortName;
                                              selected python: str(item['shortName']) == selectedItem and 'selected' or None"
                              tal:content="item/longName" />                       
                      <label for="decree-date" i18n:translate="" i18n:attributes="title" title="Insert date or range in a form (examples: 16.06.2010 ; 3.5.2010-2.5.2012 ; 1.1.10-1.1.2012)">Search by date</label><br />
                      <input type="text" size="30" id="decree-date" name="decree-date" tal:attributes="value request/decree-date|nothing" />
                 <td colspan="2">
                   <label for="decree-promoters-text" i18n:translate="" i18n:attributes="title" title="Insert number of promoter (or a comma divided list)">Search by promoter</label><br />
                   <input type="text" size="30" name="decree-promoters-text" id="decree-promoters-text" tal:attributes="value request/decree-promoters-text|nothing" /><br />
                   <select style="width: 550px;" size="1" name="decree-promoters-list"  tal:define="selectedItem request/decree-promoters-list|nothing">
                     <option value="0" i18n:translate="">-- or select from list --</option>
                     <option tal:repeat="item view/getPromoters" 
                             tal:attributes="value item/id;
                                             selected python: str(item['id']) == selectedItem and 'selected' or None"
                             tal:content="string:${item/id} - ${item/name}" />                  
                 <td colspan="2">
                   <label for="decree-fulltext" i18n:translate="" i18n:attributes="title" title="">Fulltext search</label><br />
                   **<input type="text" size="60" name="decree-fulltext" id="decree-fulltext" tal:attributes="value request/decree-fulltext|nothing" />**
                   <!-- at browser/ i created new getEscapedDecreeFulltext()
			but it always returns empty string to this field input type="text" size="60" name="decree-fulltext" id="decree-fulltext" tal:attributes="value request/getEscapedDecreeFulltext|nothing" /-->
                   <input type="submit" value="SEARCH" i18n:attributes="value" />
                   <input type="reset" value="RESET" i18n:attributes="value" />
        <table tal:define="result view/getResolutions" 
                    <th i18n:translate="">Decree</th>
                    <th i18n:translate="">Date</th>
                    <th i18n:translate="">Presenentor</th>                    
                <tr tal:repeat="row result"
                    tal:attributes="class python: 'row-odd' if (repeat['row'].odd()) else 'row-even' ">
                    <td><a tal:attributes="href string:${context/absolute_url}/@@decree?id=${row/id}&amp;type=${row/typ}&amp;suffix=${request/decree-period|nothing};
                                           target string:_blank"
                           tal:content="string: ${row/typ}mo ${row/id}/${row/jednani}"></a></td>
                    <td tal:content="python: here.toLocalizedTime(row['datum'])"></td>
                    <td tal:content="row/predkladatel"
                        tal:attributes="title row/predkladatel_nazev"></td>

in browser/ we have class

class SearchView(BrowserView):
    def getResolutions(self):
       fulltext       = self.request.get('decree-fulltext', None)
       #searching ... a lot of changes here :)
       #search only 'search-able' characters

       return result

@fredvd thank you. I dont see any js here.

What if you add a javascript to and set the text of the input field with javascript,

Maybe return the (whole) javascript from or just the "input text"


<script>myscript here ${view/get_variable} more script here</script>

should also work

Plone Foundation Code of Conduct