Ticket #636 (closed bug: fixed)

Opened 2 years ago

Last modified 2 years ago

Javascript error handling does not work for element <checkboxes>

Reported by: bballizlife Owned by: Julien
Priority: normal Milestone: Jelix 1.1 beta 1
Component: jelix:forms Version: trunk
Severity: normal Keywords:
Cc: Php version:
Review: review+ Hosting Provider:
Blocked By: Documentation needed: no
Blocking: #635

Description

Situation:

  • Using a <checkboxes> element with the required attribute
  • Submitting the form without ticking any item of the <checkboxes>

Error:

  • No javascript error telling that the element is required

Working:

  • server-side check is working and we have the error message telling that we must tick and item

Attachments

Change History

follow-up: ↓ 4   Changed 2 years ago by bballizlife

Addon:

  • after further tests, this only appears if there is only 1 item in the <checkboxes> element.

So if ticket #635 is accepted, we may close this one in won't fix as <checkboxes> could implies the use of 2 items at least. (for 1 item developer must use <checkbox>).

  Changed 2 years ago by laurentj

  • milestone set to Jelix 1.1 beta 1

  Changed 2 years ago by bastnic

  • owner set to bastnic
  • status changed from new to assigned

in reply to: ↑ 1   Changed 2 years ago by Julien

Replying to bballizlife:

Addon: * after further tests, this only appears if there is only 1 item in the <checkboxes> element. So if ticket #635 is accepted, we may close this one in won't fix as <checkboxes> could implies the use of 2 items at least. (for 1 item developer must use <checkbox>).

Hi,

I must add the following : checkboxes element can be filled with items from a dao, for example to set categories for a product. Then categories are mandatory, but we can never be sure that there will ever be at least 2 categories. As we can't know the number of items in the checkboxes element, required attribute must also work if there is only one.

So the javascript check has to be improved. I can do it if you want, as I'm working on a lot of little things in jForms these days. Let me know.

  Changed 2 years ago by bballizlife

I won't have time these days to improve it. So if you can work on it it would be great. Thanks !

  Changed 2 years ago by Julien

  • owner changed from bastnic to Julien
  • status changed from assigned to new
  • review set to review?

Here's the patch.

I also simplified the code

  Changed 2 years ago by Julien

  • status changed from new to assigned

Changed 2 years ago by Julien

missed a little thing on boolean check

  Changed 2 years ago by Julien

  • blocking 635 added

blocking #635 because Javascript validation for required checkbox (subject of #635) will only work if this ticket is commited.

  Changed 2 years ago by laurentj

The patch is ok, but I really would like to have unit test !

  Changed 2 years ago by laurentj

oups, sorry, wrong ticket

  Changed 2 years ago by laurentj

It seems ok for me, except this :

+                    for (var i = 0; i < elt.options.length; i++) {
+                        if (elt.options[i].selected)
+                            values.push(elt.options[i].value);
                     }

Are your sure that a select element have an options property on all browser ?

  Changed 2 years ago by laurentj

Ok, this in the DOM HTML spec : http://www.w3.org/TR/2003/REC-DOM-Level-2-HTML-20030109/html.html#ID-30606413

But we should verify that it is really implemented (IE for example)...

  Changed 2 years ago by Julien

I'll try on every browser I have installed and confirm if it works. I've used this property for a long time now, didn't have any problems.

  Changed 2 years ago by Julien

Hello,

checked that "options" property for select element works on following browsers :

  • Firefox 3 on linux / windows
  • Opera 9 on linux / windows
  • Google Chrome on windows
  • IE 5.1 to 7 on windows
  • Safari 3 on windows

don't have a Mac anymore here, but I'm sure it works for Firefox/Opera/Safari as these are standard compliant browsers for a long time now.

So I think this patch can be committed without any problem

  Changed 2 years ago by laurentj

  • review changed from review? to review+

It's ok then.

  Changed 2 years ago by Julien

  • status changed from assigned to closed
  • resolution set to fixed

committed in the trunk

Note: See TracTickets for help on using tickets.