TOPIC:

validate a text field based on a date 2 years 2 months ago #228028

  • Topic Author
  • DAVIDPL
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 75
  • Thanks: 0
I need to create a script that automatically assigns a value to a text field based on a date field previously entered in the form.

Example:
1.- I enter the date of birth, if it is greater than 2013 must assign a value to category that would be GREATER

2.- Introduced date of birth between 2006 and 2012, must assign a value to the ALEVIN cache

3.- Introduced date of minor birth to 2006, the category would be lower

CODIGO SCRIPT:

$mychoice1 = ["Adulto"];
$mychoice2 = ["Alevin"];
$mychoice3 = ["Menor"];
{
if([Fecha_nacimiento]) >= "01/01/2013");{
setInterval('ff_getElementByName("Categoria_edad").value=$mychoice1',500);
}
{
else([Fecha_nacimiento]) >= "01/01/2006" and < "01/01/2012");{
setInterval('ff_getElementByName("Categoria_edad").value=$mychoice2',500);

Please Log in or Create an account to join the conversation.

validate a text field based on a date 2 years 2 months ago #228071

  • mihaela
  • Offline
  • Developer
  • Developer
  • Posts: 3128
  • Karma: 105
  • Thanks: 415
Hello,

Here are the instructions to achieve what you want.

Go to your forms Advanced options > More options > Scripts > Initialization Script, set Type to Custom and paste in the following code:
function ff_codigo_init()
{  setInterval(calc, 500);
} // ff_codigo_init

function calc() {
var d1 = Date.parse(ff_getElementByName('Fecha_nacimiento').value);
var d2 = Date.parse("01/01/2013");
var d3 = Date.parse("01/01/2006");

if( d1 >= d2) {
 ff_getElementByName('Categoria_edad').value= "Adulto"; }
else if( d1 >= d3 && d1 < d2 ) { 
  ff_getElementByName('Categoria_edad').value= "Alevin"; }
else if( d1 <d3 ) { 
  ff_getElementByName('Categoria_edad').value= "Menor"; }

}
NOTE: To make the code above work as it should, Name of the date field must be 'Fecha_nacimiento' and the name of the textfield to display category must be 'Categoria_edad'.

I hope that I understood well what you wanted. I assumed that in your code it should be "01/01/2013" instead of "01/01/2012". Otherwise, for date of birth for year 2012 it wouldn't fit in any category.

Let me know if this works how you wanted.
If you have more questions, feel free to ask.

Regards,

Mihaela
The following user(s) said Thank You: DAVIDPL

Please Log in or Create an account to join the conversation.

Last edit: Post by mihaela.

validate a text field based on a date 2 years 2 months ago #228135

  • Topic Author
  • DAVIDPL
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 75
  • Thanks: 0
Thank you very much Mihaela for the code, it worked perfectly, you helped me a lot,

Now what I want is to improve some aspects to simplify the completion of the form by the user, basically it would be to automate the completion of some fields.

If the athlete is a minor (> 2013), when you enter the date of birth, I want you to automatically activate "Yes" the radio group, and "No" if you are of legal age. (<2013)

When the form starts, I would like it if the hidden fields appear hidden by the tutor because they appear when activated if in the radio group

Cód
function ff_copy3_Alta_licencia_deportista_init()
{ setInterval(calc, 500);
} // ff_copy3_Alta_licencia_deportista_init

function calc() {
var d1 = Date.parse(ff_getElementByName('Fecha_nacimiento').value);
var d2 = Date.parse("01/01/2013");
var d3 = Date.parse("01/01/2006");

if( d1 >= d2) {
ff_getElementByName('Categoria_edad').value= "3"; }
else if( d1 >= d3 && d1 < d2 ) {
ff_getElementByName('Categoria_edad').value= "2"; }
else if( d1 <d3 ) {
ff_getElementByName('Categoria_edad').value= "1"; }
else if( d1 <d2 ) {
ff_getElementByName('bfQuickMode3720662').value= 'off'; }[/color]

} // ff_copy3_Alta_licencia_deportista_init
Attachments:

Please Log in or Create an account to join the conversation.

validate a text field based on a date 2 years 2 months ago #228204

  • mihaela
  • Offline
  • Developer
  • Developer
  • Posts: 3128
  • Karma: 105
  • Thanks: 415
Hello again,

Thank you for the kind words, I'm glad that I've helped and that it worked.

Here is the code that will fill radio group value depending on the date.
function ff_copy3_Alta_licencia_deportista_init()
{  setInterval(calc, 500);
} 

function calc() {
var d1 = Date.parse(ff_getElementByName('Fecha_nacimiento').value);
var d2 = Date.parse("01/01/2013");
var d3 = Date.parse("01/01/2006");

if( d1 >= d2) {
 ff_getElementByName('Categoria_edad').value= "Minor";
//jQuery('[name="ff_nm_rad1[]"]:checked').val() = "yes";
jQuery(document).ready(function(){
document.getElementById("ff_elem13448").checked = true;
 });  
 }
else if( d1 >= d3 && d1 < d2 ) { 
  ff_getElementByName('Categoria_edad').value= "Alevin"; }
else if( d1 <d3 ) { 
  ff_getElementByName('Categoria_edad').value= "Adulto"; 
jQuery(document).ready(function(){
document.getElementById("ff_elem13448_1").checked = true;
 });  
}

}
NOTE: The important part is to replace ff_elem13448 and ff_elem13448_1 with ids of radio group options yes and no. To get the id, right-click on the circle before yes or no option and click Inspect. You will then see the ids as shown in the picture below.


Let me know if this works how you wanted.
Regarding the part for hiding elements, can you please explain a bit more how you want it to work because I didn't understand.

Regards,

Mihaela
Attachments:

Please Log in or Create an account to join the conversation.

validate a text field based on a date 2 years 1 month ago #228359

  • Topic Author
  • DAVIDPL
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 75
  • Thanks: 0
Hola Michaela

To obtain the name corresponding to the id of the joomla user table, I use the following formula:
Element properties:
Value:
<?php $user = JFactory::getUser(); return $user->get('name'); ?>

But to be able to obtain the data of the joomla custom fields, such as: (sport, club, coach), there is some way to do it, since each user has a value assigned that I want to capture in the form.

regards

Please Log in or Create an account to join the conversation.

validate a text field based on a date 2 years 1 month ago #228372

  • mihaela
  • Offline
  • Developer
  • Developer
  • Posts: 3128
  • Karma: 105
  • Thanks: 415
Hello again,

Please take a look at this crosstec.org/en/forums/3-breezingforms-f...onent-3x.html#226770 to obtain the data of the joomla custom fields.

Let me know if that helped you.

Regards,

Mihaela

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
  • 2
Moderators: ForumSupport
Time to create page: 0.066 seconds

BreezingForms Pro 1.4.7 for WordPress Released!

Available in the membership section.

Summer Sale!

Massive discounts on all subscriptions!

Get Your Subscription Here

Quick Links

Downloads

BreezingForms

ContentBuilder

BreezingCommerce

Templates

Documentation

BreezingForms

ContentBuilder

BreezingCommerce

Apprendre BreezingForms (French Community)

Apprendre et maîtriser BreezingForms par des tutoriels et exemples, le tout en français

breezingforms.eddy-vh.com

Questions et réponses sur les forums de l'AFUJ

AFUJ

Special Offer

Summer Sale! All subscriptions at a special price!

Includes prio support, all of our current and future Joomla!® extensions and Joomla!® templates for the duration of your membership.

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!