Roundup Tracker - Issues

Issue 2550961

classification
required attribute incorrectly shown when using field()
Type: behavior Severity: normal
Components: Web interface Versions: devel
process
Status: new
:
: : rouilj
Priority: normal :

Created on 2018-06-24 23:45 by rouilj, last changed 2018-06-24 23:45 by rouilj.

Messages
msg6094 Author: [hidden] (rouilj) Date: 2018-06-24 23:45
def cgi_escape_attrs(**attrs):
    return ' '.join(['%s="%s"'%(k,cgi.escape(str(v), True))
        for k,v in attrs.items()])

Using:

   <span tal:condition="python:not InBatchUpdate"
          tal:content="structure                                       
        
                       python:context.title.field(id='title',          
        
                       required="true")">title</span>


in an html template generates:

    <input name="title" required="true" value="test" type="text"
id="title" size="30">

which is incorrect. If it's in html 4/5 required takes no value, so it
should be required not required="true". For xhtml it should be
required="required".

What should probably happen for all attributes passed through the field
and other functions is:

  if the value is a string, generate attribute="string"
  if the value is True (i.e. the boolean) generate attribute
    for html and attribute="attribute" for xhtml

The functions in cgi/templating.py that need changing are:

def cgi_escape_attrs(**attrs):
    return ' '.join(['%s="%s"'%(k,cgi.escape(str(v), True))
        for k,v in attrs.items()])

def input_html4(**attrs):
    """Generate an 'input' (html4) element with given attributes"""
    _set_input_default_args(attrs)
    return '<input %s>'%cgi_escape_attrs(**attrs)

def input_xhtml(**attrs):
    """Generate an 'input' (xhtml) element with given attributes"""
    _set_input_default_args(attrs)
    return '<input %s/>'%cgi_escape_attrs(**attrs)

probably push the xhtml/html state down into cgi_escape_attrs and
check to see if the value is exactly True.

Do we need to handle False similarly to allow a user to:

            tal:content="structure                                     
          
                       python:context.title.field(id='title',          
        
                       attrs, required=False )

to delete required if set in attrs? I suppose not as the user could
delete manually if "required" in attrs...
History
Date User Action Args
2018-06-24 23:45:50rouiljcreate