Welcome, Guest
Username: Password: Remember me

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

Re: Decimal regEx problem. JS/PHP incompatibilies 05 Dec 2012 09:16 #5824

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Did you asked to our RegEx guru ?

Because I've done all I can for the moment.
You have all the tools, and you know how to debug.

I am sure you will find.

RegEx is really complex for me as well.
Many times with RegEx, I remember I had to give up an simplify the RegEx, even not working properly.
Then the PHP is doing the rest and if a data is not correct, you can check it step by step, using a PHP script which is testing all your rules, one by one.

I mean, depends you client, but I think it is not a big deal if 0.5% of the users are redirected by a PHP error. The user is asked to correct his error, and that's it.

Did you thougth about it ?

TODO :
1. see : classes/jmodel.item.php - validate()
2. override the validate() function of your concerned model.
(don't forget to call parent::validate(...))

Hope it helps.
Can I close please ?
Coding is now a piece of cake
The administrator has disabled public write access.

Re: Decimal regEx problem. JS/PHP incompatibilies 05 Dec 2012 09:46 #5829

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

Yes, I thought about the PHP validation but it's really important that I can solve this, particularly in this instance. RE: asking @g1smd: the current regex is actually his modified/streamlined version of my original and as discussed, the regex has been tested in JS in 2 separate validation tools/testers.

Can the validation process in the jQuery validator be updated to match the code in the builder's tester? It works fine there.

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: 05 Dec 2012 13:10 by JoomGuy. Reason: Removed incorrect info
The administrator has disabled public write access.

Re: Decimal regEx problem. JS/PHP incompatibilies 05 Dec 2012 12:46 #5837

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
OK, I'm finally starting to get somewhere with this error!

Right, to start with, I added my custom regex to the base rules, straight after the email rule in the file validator.php and renamed the handler by appending the number 1 to my custom handler like:
$baseRules["decimal4to21"] = array(
	"#regex"	=> '/^[0-9]{0,2}(\.[0-9]{0,2})?$/',
	"alertText" => LI_PREFIX . addslashes(JText::_("JSTORESOCIAL_FORMVALIDATOR_THIS_IS_NOT_A_VALID_EMAIL")), //JSTORESOCIAL_VALIDATOR_MUST_BE_22_DIGITS
);
I then changed the handler in my my form's XML so that it would use this rule from the validator instead of my custom rule file.

This works perfectly to validate/invalidate exactly according to my regex and therefore proves that there MUST be a difference in how custom rules are handled/rendered on the page compared with base rules. This prompted me to look at the difference and here's what I found:

For note, the only difference is that BASE rules appear in the script for my layout without single quotation marks (' ') around it resulting in the rule looking like:
"decimal4to21" : {
"regex" : /^[0-9]{0,2}(\.[0-9]{0,2})?$/,
"alertText" : '<span class="msg-prefix">• </span>This is not a valid email'
}
AS OPPOSED TO:
jQuery(document).ready(function(){var el = jQuery("#jform_test");el.validationEngine("showPrompt", "Decimal", "pass", false);});
jQuery.validationEngineLanguage.allRules.decimal4to2 = {
"regex" : new RegExp("^[0-9]{0,2}(\.[0-9]{0,2})?$", ''),
"alertText" : '<span class="msg-prefix">• </span>Must be 2.2 digits'
}
where it is creating a new rule Object. Also, please note the fact that all of the base rules are rendered wrapped with a slash (/) where as custom rules are not. I also tried changing my custom rule by prepending and appending a / but this doesn't work.

@admin, Please could you take a look at this as it appears as if custom rules need to be rendered just like base rules (as described above) to work correctly?

I found that this behaviour is not limited to just decimal fields as I first thought. The incorrect behaviour of the custom regular expressions is also evident in string/varchar fields.

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.

Re: Decimal regEx problem. JS/PHP incompatibilies 06 Dec 2012 19:37 #5868

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

Any news on this? This has to be a bug for any custom rules which is why I would say that it wasn't appropriate to close this at this time.

I know not many users seem to use custom rules but, this is (should be) one of the major time saving features in developing a good, safe and useable application. I've spent an enormous amount of time debugging to pin-point the problem and everything I've found suggests that it is the way that the custom rules are 'written' when compared to base rules.

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.
The following user(s) said Thank You: admin

Re: Decimal regEx problem. JS/PHP incompatibilies 07 Dec 2012 15:51 #5894

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

Any news? Desperate to sort this out!

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.

Re: Decimal regEx problem. JS/PHP incompatibilies 07 Dec 2012 20:03 #5907

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
I realized your suggestion.
Can you try it again please ?
Coding is now a piece of cake
The administrator has disabled public write access.

Re: Decimal regEx problem. JS/PHP incompatibilies 07 Dec 2012 22:12 #5914

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

Do you mean rebuild? Try in sandbox or re-download?

How did the workshop go?

BTW, thanks for those Docs! ;)

I translated one of them earlier with google translate and I think it will be quite straight-forward to 'neaten' up some anomalies that confuse. When I next get a decent 'break' I'll do the set.

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.

Re: Decimal regEx problem. JS/PHP incompatibilies 07 Dec 2012 22:49 #5917

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
You can upgrade : helpers/html/validator.php

Again Thanks for your days on the forum this week. Very helpful !!!

The Workshop :

There was lot of beginners, so we only had time to build a project, not to code inside.
I don't know if the tutorial is good because I didn't tested with them.

I did it several times to be sure, and I saw one mistake at least :
The name 'populateQuery()' do not exits. Undestand 'prepareQuery()'. (first chapter)
I often confuse myself with this one.

Also, I wroted it thinking to comment it and explain with the participants, so it is not explaining everything. Only the basic copy/paste steps.

Fore sure you will succeed, and enjoy. N:M, JDom custom, custom tasks, ...

And at the end ... the Google Map JDom plugin !!!
In a very basic way.

If you want first to see the final result, install com_travel.1.9.zip

That's it
Coding is now a piece of cake
The administrator has disabled public write access.
The following user(s) said Thank You: JoomGuy

Re: Decimal regEx problem. JS/PHP incompatibilies 07 Dec 2012 23:15 #5923

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

Will try it now... what's changed?

Glad it went well! Like I said before, when I get a bit more time free, I can make some tutorials for some of that stuff,
$awesome = $videos + $docs; //Super awesome!!
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.

Re: Decimal regEx problem. JS/PHP incompatibilies 07 Dec 2012 23:43 #5925

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

Thanks for that... is it related to the single quotes that were wrapping the regex previously?

Anyway, very happy!!!

I believe this fix will cure a lot of custom rule not found issues too possibly.

Thanks again!

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.

Re: Decimal regEx problem. JS/PHP incompatibilies 07 Dec 2012 23:44 #5926

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
K++ Thanks!
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.610 seconds

Get Started