Change form field value

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.

thanks @dieter

if user enter to field

id="decree-fulltext" tal:attributes="value request/decree-fulltext|nothing"
text
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/search.pt 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/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

Is this 'live search', a portlet, or after you get redirected (by normal search) to http://yoursite.com/@@search?

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
image
he gets the results of searching "dle přílohy" only , with the form above search result
image

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/search.pt

<html ....xmlns...>
	metal:use-macro="context/main_template/macros/master"
	i18n:domain="intra.decree">
<body>
<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">
              <tbody>
                <tr>
                  <td>                  
                    <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>                                          
                  </td>
                  <td>
                    <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" />                       
                    </select>
                  </td>
                </tr>
                <tr>
                  <td>
                      <label for="decree-date" i18n:translate="" i18n:attributes="title" title="Insert date or range in a form dd.mm.yyyy (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>
              </tr>
              <tr>
                 <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}" />                  
                   </select>
                 </td>
              </tr>                
              <tr>
                 <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/search.py 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" /-->
                 </td>
              </tr>
              <tr>
                 <td>
                   <input type="submit" value="SEARCH" i18n:attributes="value" />
                 </td>
                 <td>
                   <input type="reset" value="RESET" i18n:attributes="value" />
                 </td>
              </tr>
            </tbody>
          </table>            
        </form>
        
        <table tal:define="result view/getResolutions" 
               tal:condition="result"
               class="rzmo-result">
             <thead>
                <tr>
                    <th i18n:translate="">Decree</th>
                    <th i18n:translate="">Date</th>
                    <th i18n:translate="">Presenentor</th>                    
                </tr>
             </thead>  
             <tbody>
                <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>
                </tr>   
             </tbody>
        </table>           
            
    </metal:content-core>
</metal:content-core>  

in browser/search.py we have class

class SearchView(BrowserView):
    @view.memoize
    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 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

Plone Foundation Code of Conduct