Welcome, Guest
Username: Password: Remember me

TOPIC: [FIXED] Decimal regEx problem. JS/PHP incompatibilies

Decimal regEx problem. JS/PHP incompatibilies 02 Dec 2012 22:31 #5760

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Yes, \W \D & \S are all the same in PHP too. I'm no expert at all on this but for the most part, I believe that PHP and JS regular expressions are pretty compatible but, for cases where they do differ, you're right - 2 sets of rules would work perfectly!

Thanks again for all the help! Especially when I know you must be super busy working on 2.0 production which I know will be absolutely awesome! Cant wait!!! ;)

Thanks Jocelyn!

Best wishes,

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.
The following user(s) said Thank You: admin

Decimal regEx problem. JS/PHP incompatibilies 03 Dec 2012 09:48 #5761

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Hi @admin,

I'm really sorry but I'm afraid that upon further testing of this, there are some other issues. :oops:

Basically, when I re-installed my component last night after commenting out lines 54&55 of the validation helper, I tested only the validation of my decimal field in my product layout. As I said last night (or early hours this morning), it worked fine in that, if I entered values that were too long or too small, jQuery validation was kicking in to say I had an incorrect value - AWESOME! However, there is a very strange anomaly; after importing all of my inventory, categories, sections and products - data that is dependent/required in the form - I now get issues where entering a price of 20, 20.00, 123,123.00 ...123456.00 are all deemed invalid.

Also, upon saving the record, I now also get invalid boolean values on a not-required field to specify whether this product is the default or not.

I have re-tested this on another Joomla installation without any of the related data loaded as I tested for you before closing the ticket and the behaviour was exactly as I described - 0.1, 123456.00 ... 999999.99 all validate correctly and decimals out of this range invalidate correctly.

So, what is different?
Well, as I said, the only difference is that when I have dependent data loaded, it does not work. The fields that I have on the layout are:
  • Title - String/Varchar{0,255}, Required
  • Alias - String/Varchar{0,255}
  • Image - Image uploader, Required
  • Item - FK to inventory grouped by Section (Title), Category (Title) - These are the related items that I mentioned
  • Price - Decimal(8,2), Required with my custom regex
    //Handler: price8prec2scale
    ^(0?(\.(0[1-9]|[1-9]\d{0,1}))|[1-9]\d{0,5}(\.\d{1,2})?)$
  • Default - Default wizard (undefined default value)
  • Published - publishing wizard
This is very strange behaviour indeed and I cannot see where the issue is caused.
  1. Are there any reasons why commenting out lines 54/55 of the helper should cause an issue for the other fields?
  2. Why would having data loaded in my FK effect the behaviour of the validation in this way?
  3. Could the default or publishing wizards causing this?
Please could you take a look at this in the sandbox and/or a dev server/

I attach a ZIP of dummy data to load the Secions, Categories, Products and Inventory and I'll also do a quick screencast to further describe the behaviour for you and post that link here.

Part of the message is hidden for the guests. Please log in or register to see it.

Many thanks,

Gez

P.S. I'm sorry this is not resolved! I thought that we were well clear of this! :huh: :unsure:
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.

Decimal regEx problem. JS/PHP incompatibilies 03 Dec 2012 10:11 #5762

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
I can test it for you but please provide me a complete package with dataset inside. I will not import manualy your 4 csv file. If a begin to accept this, I may face such others requests by users.
I mean, I voluntary debug, but it is not included in the service and too much work.

Did you tried again to check the generated JS RegEx ?

Related datas cannot be a problem on that.
Did you flushed your cache ?

But, right now, I can try to add the feature of 2 regExs. This, yes.
Coding is now a piece of cake
The administrator has disabled public write access.

Decimal regEx problem. JS/PHP incompatibilies 03 Dec 2012 10:16 #5763

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Was it working before to comment the lines ?
Coding is now a piece of cake
The administrator has disabled public write access.

Decimal regEx problem. JS/PHP incompatibilies 03 Dec 2012 10:32 #5764

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
admin wrote:
I can test it for you but please provide me a complete package with dataset inside. I will not import manualy your 4 csv file. If a begin to accept this, I may face such others requests by users.
I mean, I voluntary debug, but it is not included in the service and too much work. --- How best can I repackage the whole thing? (Sure, I understand that and I appreciate your help here!!!)

Could you please check in the builder? I mean, of course there is dummy data there but, you are more than welcome to try it, then remove the data.


Did you tried again to check the generated JS RegEx ? --- Yes, I have the helper lines commented out and the regex appears exactly as I input it into the builder

Related datas cannot be a problem on that.
Did you flushed your cache ? --- I did not flush my cache however, I have 2 Joomla installations running side by side... 1 with data, the other without data and they behave totally differently

But, right now, I can try to add the feature of 2 regExs. This, yes.
Thanks Jocelyn!

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.

Decimal regEx problem. JS/PHP incompatibilies 03 Dec 2012 10:36 #5765

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Just emailed you at support address subject: Decimal Field Issues

Please let me know what you think,

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.

Decimal regEx problem. JS/PHP incompatibilies 03 Dec 2012 10:39 #5766

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
I've just uploaded the new feature for you :

in your rule file, you have the protected var $regex, with your regex.
Just under, if you define $regexJs, it will override it for Javascript.

And the 2 lines are reactivated.

Tell me if it helps you..
Coding is now a piece of cake
The administrator has disabled public write access.

Decimal regEx problem. JS/PHP incompatibilies 03 Dec 2012 10:44 #5767

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
And the files to upgrade are :
- helpers/html/validator.php
- classes/rule.php
Coding is now a piece of cake
The administrator has disabled public write access.

Decimal regEx problem. JS/PHP incompatibilies 03 Dec 2012 10:45 #5768

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
admin wrote:
I've just uploaded the new feature for you :

in your rule file, you have the protected var $regex, with your regex.
Just under, if you define $regexJs, it will override it for Javascript.

And the 2 lines are reactivated.

Tell me if it helps you..
Do you mean reactivate lines 54 & 55 of the validation helper?

Thanks!

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.

Decimal regEx problem. JS/PHP incompatibilies 03 Dec 2012 10:50 #5770

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Yes, because I understood your issue was since this change.

So, can you make few tests with or without it ?
And also, you can use regexJs var declaration in your rules files.
Coding is now a piece of cake
The administrator has disabled public write access.

Decimal regEx problem. JS/PHP incompatibilies 03 Dec 2012 11:10 #5772

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
No probs!

Will check them now and post back. I'll be 10-15 mins because I need to regenerate, reinstall and re-import the data.

Will post back here as soon as done!

Thanks,

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.

Decimal regEx problem. JS/PHP incompatibilies 03 Dec 2012 12:11 #5774

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Hi @admin,

OK, I've restored everything as suggested but still not completely working. If I enter 1, 0.1 - 0.9, 0.01 - 0.09 it validates OK and values save.

If I enter 0.10, 0.99, 1.1, 1.10 ... 999999.99 it says that the number is invalid. 0.01 - 999999.99 are validated correctly in JS when tested at the tester website I linked to before.

On a positive note, it is preventing out of range numbers from saving however, obviously it is not allowing the above in-range numbers to save

Many thanks,

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.

Decimal regEx problem. JS/PHP incompatibilies 03 Dec 2012 12:26 #5778

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
One other question as I think we might have overlooked this...

In the builder, the built in tester works fine to validate/invalidate exactly what I expect. Is there something else going on here? Are the Regexp's being converted for use with PHP or is something else?

If it works in JS in the builder is there some legacy code to do with rules that's playing a part here?

Thanks,

Gez
*************ADD**************
Also, sorry, I forgot to mention this but, this is one of the reasons I thought that the transformation might be happening somewhere else or in another way... The protected $regex is always the same as my inputed expression. When I copy my original regex into a new $regexJs var, they appear the same:
protected $regex = '^(0\.(0[1-9]|[1-9]\d?)|[1-9]\d{0,5}(\.\d{1,2})?)$';
protected $regexJs = '^(0\.(0[1-9]|[1-9]\d?)|[1-9]\d{0,5}(\.\d{1,2})?)$';
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
Last Edit: 03 Dec 2012 13:08 by JoomGuy. Reason: ADD
The administrator has disabled public write access.

Decimal regEx problem. JS/PHP incompatibilies 03 Dec 2012 17:04 #5794

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Hi Jocelyn,

I thought I had this working a moment ago so I deleted what I thought were now 'irrelevant' posts however, I cannot get it to work.

Earlier, when this wasn't working, I changed a few things to debug/fault-find including;
FROM:
if ($rule->regexJs)
	$regex = $rule->regexJs;
TO:
if ($rule->regexJs != NULL && $rule->regexJs != ''){
	$regex = preg_replace("/\\\\/", "\\", $rule->regexJs);
}
After lots of back and forth, I finally thought it was fixed so I deleted my posts. As I was posting my findings, I began to remove each newly added block 1 at a time to retest and it all went wrong...

Is there anyway you can restore my deleted posts from the thread?

One of my earlier posts included: Is it possible that we're only having this issue and having to circumvent it with the new $regexJs var/property because of some legacy code in rules or something? I just don't understand how the original regex validates correctly in the builder's tester and on the online tester I pointed to at tools.netshiftmedia.com/regexlibrary/

Can the regex handler use the same code as is used in the builder for testing? This works perfectly in the builder ;)

*********ADD************
//price8prec2scale Rule File
protected $regex = '^(0\.(0[1-9]|[1-9]\d?)|[1-9]\d{0,5}(\.\d{1,2})?)$';
protected $regexJs = '^(0\.(0[1-9]|[1-9]\d?)|[1-9]\d{0,5}(\.\d{1,2})?)$';
Currently, with both $regex & $regexJs protected properties set the same as each other as I believe they should be to prevent any replacement of the \d, \w and \s modifiers. However, with this set I cannot validate numbers/decimals that are really in range so, 0.11, 1, 123, 123456, 123456.00 and 999999.99 all invalidate. 0.1, 0.01, 0.9 and single digits are all validating ok.

I've also echo'd "JS' . $regex" inside of the IF statement so that I can be sure that it is using the JS regex and not the regular one. This is working fine and displaying that the field is in fact using the JS regex. Also, I'm flushing cache every time I test so I can be sure that it is not caching the rule in the jQuery validation.

Please any help with this would be massively appreciated!

Thanks,

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
Last Edit: 04 Dec 2012 09:29 by JoomGuy. Reason: UPDATED INFO
The administrator has disabled public write access.

Re: Decimal regEx problem. JS/PHP incompatibilies 04 Dec 2012 09:36 #5801

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
notify of edit previous

Also, just to note that I've now returned the validator helper to exactly as you had it:
if ($rule->regexJs)
	$regex = $rule->regexJs;
else
{...
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.
Time to create page: 0.115 seconds

Get Started