another workaround (without jquery) is (exemplifying):

''' replace <my_table>, <my_field_date_name> with your own values '''
### controller ###
def my_controller:
 form = SQLFORM(db.my_table,formstyle = 'bootstrap')
 if form.process().accepted:
 response.flash = 'form accepted'
 elif form.errors:
 response.flash = 'form has errors'
 else:
 response.flash = 'please fill out the form'
 return dict(form=form)


### view ###
{{extend 'layout.html'}}
{{
inpt_with_addon = form.element(_name='my_field_date_name',replace=lambda me:
DIV(me,SPAN(TAG.I(_class='icon-calendar'),_class="add-on"),_class=
'input-append'))
import re
if form.errors:
    for key, value in form.errors.iteritems():
        inpt = form.element(_name=key)
        inpt_wrapper = inpt.parent
        if not "controls" in inpt_wrapper['_class']:
            inpt_wrapper = inpt.parent.parent
        pass
        inpt_wrapper.parent['_class'] += ' error'
        inpt_wrapper.element(_class=re.compile('help-inline'),replace=lambdame
:SPAN(value,_class=me['_class']))
    pass
    form.errors.clear()
pass
}}


{{=form}}


Il giorno lunedì 29 ottobre 2012 21:44:59 UTC+1, Richard ha scritto:
>
> I work around my problem like this :
>
> Add this little script in the view
>
> <script>
> jQuery(document).ready(function(){
>     jQuery('.input_wrapper').has('.error').addClass("inputError"); // Add 
> bootstrap class "inputError" to .input_wrapper div when there is error. 
> Note .input_wrapper div is only there for field with bootstrap "add-on" 
> class, since it would have required to alter SQLFORM to set a 
> .input_wrapper div to every input field I think...
>     jQuery('.w2p_fw').has('.error').addClass("control-group error"); // 
> Add bootstrap class "control-group error" to .w2p_fw when there is error
>     jQuery('.w2p_fw').each(function(){
>         $(this).find('.error_wrapper').appendTo(this); // I move the 
> .error_wrapper div at the end of the .w2p_fw for each .w2p_fw
>     });
> });
> </script>
>
> Write custom widget :
>
> def app_date_widget(field, value, placeholder='YYYY-MM-DD'):
>     return DIV(INPUT(_name=field.name,
>                  _id="%s_%s" % (field._tablename, field.name),
>                  _class=field.type,
>                  _value=value,
>                  _placeholder=T(placeholder),
>                  requires=field.requires),
>                  SPAN(I(_class='icon-calendar'), _class='add-on'),
>                  _class='input_wrapper input-append' # input-append is a 
> bootstrap class required to make work add-on we create the input_wrapper 
> for this
>                  )
>
> And set the widget to my table field :
>
>     Field('test_date','date',
>         notnull=True,
>         requires=[IS_NOT_EMPTY(error_message=T('field can\'t be empty')),
>             IS_DATE(format=T('%Y-%m-%d'),error_message=T('valid date of 
> format : YYYY-MM-DD'))],
>         required=True,
>         widget=app_date_widget
>         )
>
>
>
> On Mon, Oct 29, 2012 at 11:47 AM, Richard <ml.richa...@gmail.com<javascript:>
> > wrote:
>
>> Hello,
>>
>> I am searching for a way to use bootstrap input-append and add-on.
>>
>> <div class="w2p_fw">
>>  <input class="date" id="table_date" name="date" placeholder="YYYY-MM-DD" 
>> type="text" value="">
>>  <span class="add-on"><i class="icon-calendar"></i></span>
>> </div>
>>
>>
>> The problem is that when the error trigger the error get between the 
>> input and the span like this :
>>
>> <div class="w2p_fw input-append control-group error">
>>  <input class="date invalidinput inputError" id="table_date" name="date" 
>> placeholder="YYYY-MM-DD" type="text" value="">
>> * <div class="error_wrapper">*
>> * <div class="error" id="date__error" style="display: inline-block; 
>> ">can't be empty</div>*
>> * </div>*
>> <span class="add-on"><i class="icon-calendar"></i></span>
>> </div>
>>
>> Even if I put the input and span in a div :
>>
>> <div class="w2p_fw">
>> * <div class="input-append control-group error">*
>>  <input class="date invalidinput inputError" id="table_date" name="date" 
>> placeholder="YYYY-MM-DD" type="text" value="">
>> * <div class="error_wrapper">*
>> * <div class="error" id="date__error" style="display: inline-block; 
>> ">can't be empty</div>*
>> * </div>*
>> <span class="add-on"><i class="icon-calendar"></i></span>
>> * </div>*
>> </div>
>>
>>
>> I see no way to fix that except refactoring html.py INPUT class near line 
>> 1793, but I am not sure if it will cause a backward incompatibility...
>>
>> Richard
>>
>> -- 
>>  
>>  
>>  
>>
>
>

-- 



Reply via email to