? Success

User tests: Successful: Unsuccessful:

avatar piotrmocko
piotrmocko
4 Mar 2015

Previously isValid method was looking once for fields to validate and second time for invalid fields. Now it filters fields which were already found at the beginning.

Previously when invalid field was found, it was not using label from DATA attribute which was created on validator initialization, but it was looking for label one more time, depending only on attribute FOR, instead of ID.

This patch makes only improvements and fixes labels. You can only test if validation still works.
Go to new article view and try to save without any title. You will see error message with invalid field label.
Remember to enable debug mode in Global Configuration as this patch contains only uncompressed file.

Which tool do you use in Joomla to compress JS, that I could create one?

Lately when I was developing a component I had problems with labels. I was creating new fields on the fly and I was attaching data attribute with existing label and it was not working as rendering error message was not consistent with method attachToForm.

In attachToForm method jQuery.each has been changed to FOR loop which is much faster.
isValid method can also be attached to which is also a submit button.
validate method will no longer be attached to buttons as it should only be attached to fields.

avatar piotrmocko piotrmocko - open - 4 Mar 2015
avatar joomla-cms-bot joomla-cms-bot - change - 4 Mar 2015
Labels Added: ?
avatar zero-24 zero-24 - change - 4 Mar 2015
Category JavaScript
avatar n9iels
n9iels - comment - 4 Mar 2015

@test No problems found, code looks also good to me.

I'am not sure, but I think you can use a random javascript compressor like: http://javascriptcompressor.com/
Or will this files compressed automatically when creating the next build?


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/6294.
avatar n9iels n9iels - test_item - 4 Mar 2015 - Tested successfully
avatar Fedik
Fedik - comment - 4 Mar 2015

looks not bad, but I see one more thing to optimize :smile:

about compress JS look https://gist.github.com/phproberto/6933178

avatar piotrmocko
piotrmocko - comment - 4 Mar 2015

@Fedik I have followed your idea and I have made an array with invalid fields

avatar Fedik
Fedik - comment - 4 Mar 2015

thanks :+1:
you now can replace .each to

for(var i, l = invalid.length; i < l; i++ ) {
  label = jQuery(invalid[i]).data('label');
 ...
 ...
}

it a little bit faster http://jsperf.com/for-vs-foreach/37 :smile:

avatar piotrmocko
piotrmocko - comment - 4 Mar 2015

Thanks for a nice test with loops, that was interesting. I have updated code.

avatar piotrmocko
piotrmocko - comment - 4 Mar 2015

What do you think about one more improvement as for loop is much faster than $.each?
It could be improved in isValid and attachToForm methods.

var fields = jQuery(form).find('input, textarea, select, fieldset, button') || [];
for(var i, l = fields.length; i < l; i++ ) {
    ...
}
avatar Fedik
Fedik - comment - 4 Mar 2015

yes, good idea

avatar piotrmocko
piotrmocko - comment - 4 Mar 2015

Patch ready to test again. I have made further improvements to isValid and attachToForm methods.

avatar piotrmocko piotrmocko - change - 4 Mar 2015
The description was changed
Title
Optimized isValid method in JavaScript validator
Optimized JavaScript validator
avatar Fedik
Fedik - comment - 4 Mar 2015

looks good,
left only one important thing: compressed version :wink:

avatar piotrmocko
piotrmocko - comment - 4 Mar 2015

All improvements done

avatar Fedik
Fedik - comment - 4 Mar 2015

all good except one thing, it not work on administrator/index.php?option=com_menus&view=menu&layout=edit :smile:
replacing to label = jQuery(invalid[i]).data("label"); opened hidden bug .... see code comments

avatar piotrmocko
piotrmocko - comment - 4 Mar 2015

Thank you @Fedik for great cooperation :)

avatar Fedik
Fedik - comment - 4 Mar 2015

do not forget update compressed version :wink:

avatar Fedik
Fedik - comment - 5 Mar 2015

one more thing, could we fix order for error messages ?
currently it reversed form fields order:
screen 2015-03-05 11 00 07 455x360

it very simple, just change for() to reversed for (i = invalid.length - 1; i >= 0; i--) { inside if (!valid && invalid.length > 0) {

thanks!

avatar Fedik
Fedik - comment - 5 Mar 2015

thanks! :+1:

test
works good,

one more tester? :smile:

avatar Fedik Fedik - test_item - 5 Mar 2015 - Tested successfully
avatar n9iels
n9iels - comment - 5 Mar 2015

@test works fine for me! Also the field order is correct


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/6294.
avatar brianteeman
brianteeman - comment - 5 Mar 2015

Setting RTC


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/6294.
avatar brianteeman brianteeman - change - 5 Mar 2015
Status Pending Ready to Commit
avatar brianteeman brianteeman - change - 5 Mar 2015
Labels Added: ?
avatar zero-24 zero-24 - close - 13 Mar 2015
avatar phproberto phproberto - change - 13 Mar 2015
Status Ready to Commit Closed
Closed_Date 0000-00-00 00:00:00 2015-03-13 09:37:55
avatar phproberto phproberto - close - 13 Mar 2015
avatar phproberto phproberto - close - 13 Mar 2015
avatar phproberto
phproberto - comment - 13 Mar 2015

Merged. Thanks!

avatar zero-24 zero-24 - change - 14 Oct 2015
Labels Removed: ?

Add a Comment

Login with GitHub to post a comment