248 Posts
Giuse
7 years ago
Topic

Hi, I made some tests with the function validation plugin. The validation works but I found a couple of problems with the alert message (when validation fails):

  • the string returned by the function is displayed, and not the alert message set in the plugin: is it a bug?
  • how to have multilanguage messages? I tried to return a J(ALERT_MESSAGE) from the function but it does not seem to work.

cheers

Giuse

Get a VIP membership
248 Posts
Giuse
7 years ago
0
Level 1

Hi, while waiting for this information (especially how to use multilanguage in function validation plugin), I noticed that also the ajax availability validation popup ("Available") is not translated: I searched "Available" in override language to find to constant to translate but I didn't find it - could you please tell me which is the constant to map (or if the mapping is missing and the string is directly typed into the code - we could open a PR on GitHub for that)?

thanks!

Giuse

4229 Posts
Kadministrator
7 years ago
6
Level 1

Did you activate jtext function in seblod configuration?

248 Posts
Giuse
7 years ago
5
Level 2

Sure :), it is widely used in all the site: some alerts (max/min characters required, URL format) ARE translated, the "Available"/"Not Available" are not translated. Same with function validation plugin: if I put "KO" as return result of the function, the popup is "KO" while I would expect a "COM_CCK_KO" with JTEXT enabled

cheers

Giuse

248 Posts
Giuse
7 years ago
4
Level 3

Hi Klas, do you have a feedback on this? Thanks a lot

Giuse

4229 Posts
Kadministrator
7 years ago
3
Level 4

to return translated message your function must look like this. ALso see

https://github.com/posabsolute/jQuery-Validation-Engine#funccallmethodname

function validatef (field, rules, i, options){
  if (field.val() != "HELLO") {
     return options.allrules.function_YOUR_FIELD_NAME.alertText;

  }
}
248 Posts
Giuse
7 years ago
2
Level 5

sorry Klas, but it's really not clear for me: where should I put the JTEXT string for returning a custom message in 

options.allrules.function_YOUR_FIELD_NAME.alertText;

 ? In the alertText? Also I tried to copy&paste your code and seems not to work in the Seblod plugi, maybe it is more general code. The code that works is like

myvalidation = function(){

var text = $(this).attr(<field_name>).value;

var msg;

if ( text != <some_value> ) {

msg="KO";

}

return msg;

}




but I get "KO" and not "COM_CCK_KO" , that's why I am asking for a workable example of multilanguage alert. The plugin page in the Store does not give directions on this.

Also the message in alert field is not clear in usage: the validation popup is the message returned by the custom function, so where to use the alert field?

We can then update the plugin page with these clarification, I am available to write them down when understood if you like.

thanks again

Giuse

4229 Posts
Kadministrator
7 years ago
1
Level 6

Hi,

  • Enter KO in the function validation configuration as message.
  • Add "COM_CCK_KO" to the language override
  • Then you will get tranlslated message in the options.allrules.function_YOUR_FIELD_NAME.alertText property. You probably missed here that you need to replace YOUR_FIELD_NAME with your actual field name e.g. options.allrules.function_art_title.alertText. 

You can than return this translated message directly or add some string to it before you return it.You will need to use code as in my example as otherwise you won't be able to access this property.

248 Posts
Giuse
7 years ago
0
Level 7

Thanks, now the whole picture is clear, the .alertText is the parameter to put in alert message of the plugin!

Maybe this example with multilanguage may be put in the plugin page.

cheers

Giuse

Get a VIP membership