web2py / py4web

Other
251 stars 126 forks source link

Error in Form() generating the html of the field labels when there is no table #728

Closed cdb88 closed 2 years ago

cdb88 commented 2 years ago

The for attribute of

Should be for="no_table_c_accept" but it renders like this for="none_c_accept"

   form = Form(
        table=[
            Field('c_accept', 'boolean', label='Acepto')
        ],
        keep_values=True,
    )

<span class="">
    <input class="" id="no_table_c_accept" name="c_accept" type="checkbox" value="ON">
</span>
<label class="" for="no_table_c_accept" style="display: inline !important"> Acepto</label>

Correct:

<span class="">
    <input class="" id="no_table_c_accept" name="c_accept" type="checkbox" value="ON">
</span>
<label class="" for="none_c_accept" style="display: inline !important"> Acepto</label>

I think the solution is in line 346 of the Form.py file

- input_id = "%s_%s" % (field.tablename, field.name)
+ input_id = to_id(field)
jpsteil commented 2 years ago

I think the fix is actually in line 719 in form.py

form_name = form_name or 'none'

should be

form_name = form_name or 'no_table'

Can you submit a PR?

If not, I'll try to get time today.

-Jim

On Thu, May 19, 2022 at 11:05 AM cdb88 @.***> wrote:

The for attribute of is incorrect,

Should be for="no_table_c_accept" but it renders like this for="none _c_accept"

form = Form( table=[ Field('c_accept', 'boolean', label='Acepto') ], keep_values=True, )

Correct:

I think the solution is in line 346 of the Form.py file

  • inputid = "%s%s" % (field.tablename, field.name)
  • input_id = to_id(field)

— Reply to this email directly, view it on GitHub https://github.com/web2py/py4web/issues/728, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABMKF5UWD7X7AYMY7PGO7JLVKZRFZANCNFSM5WMW7T2Q . You are receiving this because you are subscribed to this thread.Message ID: @.***>

cdb88 commented 2 years ago

Thank you very much for responding so quickly.

I have never done a PR :-( sorry, I promise to learn how to do it.

I have tried your solution, but it doesn't work well.

With the example above it works fine, but if I use the parameter form_name="form_1" it doesn't work.

The id attribute of always starts with "no_table" even when form_name is used.

The for attribute of

I guess we'll have to look at it more slowly, to be consistent with the name of the table.

jpsteil commented 2 years ago

I'll check it again after lunch.

Jim

On Thu, May 19, 2022, 11:49 AM cdb88 @.***> wrote:

Thank you very much for responding so quickly.

I have never done a PR :-( sorry, I promise to learn how to do it.

I have tried your solution, but it doesn't work well.

With the example above it works fine, but if I use the parameter form_name="form_1" it doesn't work.

The id attribute of always starts with "no_table" even when form_name is used.

The for attribute of does not have the same behavior.

I guess we'll have to look at it more slowly, to be consistent with the name of the table.

— Reply to this email directly, view it on GitHub https://github.com/web2py/py4web/issues/728#issuecomment-1131952427, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABMKF5UBB4R5GLJ4SEAOMEDVKZWJXANCNFSM5WMW7T2Q . You are receiving this because you commented.Message ID: @.***>

jpsteil commented 2 years ago

After looking further I think we should wait until Massimo has a chance to look at it to make sure all is in alignment.

I'm not sure the intent of the form_name parameter and how 'no_table' should be set.

Another fix I tried that seems to work is first undo my first suggestion and then on line 721, change

field.tablename = getattr(field, "tablename", form_name)

to

field.tablename = getattr(field, "tablename", "no_table")

I say that because the function

def toid(field): """get an identified for a field""" return "%s%s" % (getattr(field, "_tablename", "no_table"), field.name)

Seems to set that id to 'no_table' regardless of the formname passed in.

Does that seem to work for you?

-Jim

On Thu, May 19, 2022 at 11:51 AM Jim Steil @.***> wrote:

I'll check it again after lunch.

Jim

On Thu, May 19, 2022, 11:49 AM cdb88 @.***> wrote:

Thank you very much for responding so quickly.

I have never done a PR :-( sorry, I promise to learn how to do it.

I have tried your solution, but it doesn't work well.

With the example above it works fine, but if I use the parameter form_name="form_1" it doesn't work.

The id attribute of always starts with "no_table" even when form_name is used.

The for attribute of does not have the same behavior.

I guess we'll have to look at it more slowly, to be consistent with the name of the table.

— Reply to this email directly, view it on GitHub https://github.com/web2py/py4web/issues/728#issuecomment-1131952427, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABMKF5UBB4R5GLJ4SEAOMEDVKZWJXANCNFSM5WMW7T2Q . You are receiving this because you commented.Message ID: @.***>

cdb88 commented 2 years ago

This solution seems to work fine for me.