It probably would be more beneficial to look at the validators.py
class IS_IN_SET(Validator):

add print statements to see why it isn't working.

On Thu, Mar 1, 2012 at 7:05 AM, Cliff <[email protected]> wrote:

> Running 1.99.4
>
> I have not been able to get the IS_IN_SET validator to work properly.
> I don't know why this should be.
>
> When used with SQLFORM to edit a record, the select field refuses to
> show the current value of the field.  Instead it shows the first value
> in the list or the zero value for the field.
>
> So I made an alternative widget.  The code consists of two functions,
> below.
>
> If you are having similar problems, feel free to use it.
>
> The _style definition at the end of the call is there to make sure I
> was seeing my widget instead of the default.  It is not necessary for
> the widget to work.
>
> ############################################################
>
> def is_it_selected(current_value, option, multiple):
>    if len(current_value) == 1 or not multiple:
>        current_value=current_value[0]
>        if current_value==option:
>            out = 'selected'
>        else:
>            out = None
>    else:
>        if option in current_value:
>            out='selected'
>        else:
>            out=None
>    return out
>
> def my_select_widget(field,value):
>    # diagnostics uncomment to learn
>    #print 'value'
>    #print value
>    #print 'type(value)'
>    #print type(value)
>
>    f = str(field)
>    f_name = f.split('.')[-1]
>    f_id = f.replace('.', '_')
>    f_requires = db[request.controller][f_name].requires
>    the_set = f_requires.theset
>    the_multiple = f_requires.multiple
>    option_set = []
>    for t in the_set:
>        is_selected = is_it_selected(value, t, the_multiple)
>        option_set.append(OPTION(t, _selected = is_selected))
>    return SELECT(option_set, _name='status', _id='buckslips_status',
>         _style='color:red;'
>    )




-- 
-- 
Regards,
Bruce Wade
http://ca.linkedin.com/in/brucelwade
http://www.wadecybertech.com
http://www.warplydesigned.com
http://www.fitnessfriendsfinder.com

Reply via email to