[SOLVED] Javascript | Problem getvalue triggered with a button element in repeat group + SOLUTION

marcq

Member
Hi,

I would like to get value from my form into a repeat group with javascript. The trigger is a button element which call a javascript function.

This function was working when the group wasn't a repeat group :

JavaScript:
function inheritF59oF44fe1() {

  // GET FORM REFERENCE
  var form = Fabrik.getBlock('form_59');

  // GET VALUES
  var type = 3;
  var no = 1;

  var userid = form.formElements.get('gprh_fabrik_user_registration___id').getValue();
  var name = form.formElements.get('gprh_fabrik_user_registration___cp_name').getValue();
  var firstname = form.formElements.get('gprh_fabrik_user_registration___cp_firstname').getValue();
  var address_1 = form.formElements.get('gprh_fabrik_user_registration___cp_address_1').getValue();
  var address_2 = form.formElements.get('gprh_fabrik_user_registration___cp_address_2').getValue();
  var zip = form.formElements.get('gprh_fabrik_user_registration___cp_zip').getValue();
  var city = form.formElements.get('gprh_fabrik_user_registration___cp_city').getValue();
  var email = form.formElements.get('gprh_fabrik_user_registration___cp_email').getValue();

  // OPEN FORM 44 AND POPULATE THE FIELDS
  window.open('http://www.webamazingapps.com/projects/gprh.ch/index.php/gestion-membres-2/suivi-administratif/gestion-courriers-rappel/creer-un-courrier-rappel-sa?gprh_fabrik_user_reminder___bloc_destinataire=' + email + '&gprh_fabrik_user_reminder___type_rappel=' + type + '&gprh_fabrik_user_reminder___no_rappel=' + no + '&gprh_fabrik_user_reminder___userid=' + userid + '&gprh_fabrik_user_reminder___cp_name=' + name + '&gprh_fabrik_user_reminder___cp_firstname=' + firstname + '&gprh_fabrik_user_reminder___cp_address_1=' + address_1 + '&gprh_fabrik_user_reminder___cp_address_2=' + address_2 + '&gprh_fabrik_user_reminder___cp_zip=' + zip + '&gprh_fabrik_user_reminder___cp_city=' + city);
   };

No clue how to get those value would appreciate your support.

Cheers, marc
 
Well, once you repeat a group, the ids have their numeric sequence in the group appended, so we know which one belongs to which repeat. So gprh_fabrik_user_registration___cp_name_0, gprh_fabrik_user_registration___cp_name_1 etc.

Is your button itself within the repeat group? If so, then you can work out what repeat it's in ...

First off, assuming you are calling this function from a 'click' event in the Javascript settings for the button element, pass 'this' as a parameter ...

Code:
inheritF59oF44fe1(this);

JavaScript:
function inheritF59oF44fe1(el) {

  var repeat = el.getRepeatNum();

  // GET VALUES
  var type = 3;
  var no = 1;

  var userid = el.form.formElements.get('gprh_fabrik_user_registration___id_' + repeat).getValue();
  var name = el.form.formElements.get('gprh_fabrik_user_registration___cp_name_' + repeat).getValue();
  var firstname = el.form.formElements.get('gprh_fabrik_user_registration___cp_firstname_' + repeat).getValue();
  var address_1 = el.form.formElements.get('gprh_fabrik_user_registration___cp_address_1_' + repeat).getValue();
  var address_2 = el.form.formElements.get('gprh_fabrik_user_registration___cp_address_2_' + repeat).getValue();
  var zip = el.form.formElements.get('gprh_fabrik_user_registration___cp_zip_' + repeat).getValue();
  var city = el.form.formElements.get('gprh_fabrik_user_registration___cp_city_' + repeat).getValue();
  var email = el.form.formElements.get('gprh_fabrik_user_registration___cp_email_' + repeat).getValue();

  // OPEN FORM 44 AND POPULATE THE FIELDS
  window.open('http://www.webamazingapps.com/projects/gprh.ch/index.php/gestion-membres-2/suivi-administratif/gestion-courriers-rappel/creer-un-courrier-rappel-sa?gprh_fabrik_user_reminder___bloc_destinataire=' + email + '&gprh_fabrik_user_reminder___type_rappel=' + type + '&gprh_fabrik_user_reminder___no_rappel=' + no + '&gprh_fabrik_user_reminder___userid=' + userid + '&gprh_fabrik_user_reminder___cp_name=' + name + '&gprh_fabrik_user_reminder___cp_firstname=' + firstname + '&gprh_fabrik_user_reminder___cp_address_1=' + address_1 + '&gprh_fabrik_user_reminder___cp_address_2=' + address_2 + '&gprh_fabrik_user_reminder___cp_zip=' + zip + '&gprh_fabrik_user_reminder___cp_city=' + city);
   };


So ... by passing 'this' (the element object) into the function (which we reference as 'el' in the function args) we can then get the repeat number for it using el.getRepeatNum(). Which we can then append to the ids in the el.form.formElements.get(). Also note that because we have the 'el' object, which knows what form it is on (in el.form) we can use el.form instead of doing the getBlock().

if you button isn't in the repeat group, then obviously there's the logic problem of "which repeat are you wanting to use?".

-- hugh
 
Hi Hugh,

Thank you for your clear and explanations. It is working now !

I could use your code with a little change since the values I get are not in a repeated group I didn't need the numeric sequence :

JavaScript:
function inheritF59ToF44co1(el) {

  var repeat = el.getRepeatNum();

  // GET VALUES
  var type = 4;
  var no = 1;

  var userid = el.form.formElements.get('gprh_fabrik_user_registration___id').getValue();
  var name = el.form.formElements.get('gprh_fabrik_user_registration___cp_name').getValue();
  var firstname = el.form.formElements.get('gprh_fabrik_user_registration___cp_firstname').getValue();
  var address_1 = el.form.formElements.get('gprh_fabrik_user_registration___cp_address_1').getValue();
  var address_2 = el.form.formElements.get('gprh_fabrik_user_registration___cp_address_2').getValue();
  var zip = el.form.formElements.get('gprh_fabrik_user_registration___cp_zip').getValue();
  var city = el.form.formElements.get('gprh_fabrik_user_registration___cp_city').getValue();
  var email = el.form.formElements.get('gprh_fabrik_user_registration___cp_email').getValue();

  // OPEN FORM 44 AND POPULATE THE FIELDS
  window.open('http://www.webamazingapps.com/projects/gprh.ch/index.php/gestion-membres-2/suivi-administratif/gestion-courriers-rappel/creer-un-courrier-rappel-sa?gprh_fabrik_user_reminder___bloc_destinataire=' + email + '&gprh_fabrik_user_reminder___type_rappel=' + type + '&gprh_fabrik_user_reminder___no_rappel=' + no + '&gprh_fabrik_user_reminder___userid=' + userid + '&gprh_fabrik_user_reminder___cp_name=' + name + '&gprh_fabrik_user_reminder___cp_firstname=' + firstname + '&gprh_fabrik_user_reminder___cp_address_1=' + address_1 + '&gprh_fabrik_user_reminder___cp_address_2=' + address_2 + '&gprh_fabrik_user_reminder___cp_zip=' + zip + '&gprh_fabrik_user_reminder___cp_city=' + city);
   };

"GetValues" are passed to form_44 and populating the fields accordingly.

Thanks a lot Hugh for your oustanding support.

Cheers, marc
 
OK, I'm a little confused as you don't seem to be using the 'repeat' variable anywhere, but as long as it works ...

-- hugh
 
Solution from Hugh to whom it may interest :

JavaScript:
function inheritF59ToF44co1(el) {

// GET FORM REFERENCE
var form = Fabrik.getBlock('form_59');

// GET REPEAT GROUP NUMBER
var repeat = el.getRepeatNum();

// GET VALUES
var type = 4;
var no = 1;

var userid = el.form.formElements.get('gprh_fabrik_user_registration___id').getValue();
var name = el.form.formElements.get('gprh_fabrik_user_registration___cp_name').getValue();
var firstname = el.form.formElements.get('gprh_fabrik_user_registration___cp_firstname').getValue();
var address_1 = el.form.formElements.get('gprh_fabrik_user_registration___cp_address_1').getValue();
var address_2 = el.form.formElements.get('gprh_fabrik_user_registration___cp_address_2').getValue();
var zip = el.form.formElements.get('gprh_fabrik_user_registration___cp_zip').getValue();
var city = el.form.formElements.get('gprh_fabrik_user_registration___cp_city').getValue();
var email = el.form.formElements.get('gprh_fabrik_user_registration___cp_email').getValue();

  // COTISATION : PREMIER RAPPEL
var invoice_co = el.form.formElements.get('gprh_fabrik_user_registration_333_repeat___date_envoi_facture_co_' + repeat).getValue();
var bloc_introduction_co1_1 = 'Le ';
var bloc_introduction_co1_2 = ', nous vous faisions parvenir un bulletin de versement afin d\'acquitter votre cotisation pour l\'ann?e en cours dans un d?lai de 30 jours.';
var bloc_introduction_co1   = bloc_introduction_co1_1 + invoice_co + bloc_introduction_co1_2;
var bloc_situation_co1_1    = 'A ce jour, et sauf erreur de notre part, le montant de votre cotisation ne nous a pas ?t? cr?dit?.';
var bloc_attentes_co1_1       = 'Nous vous remercions par avance de bien vouloir r?gulariser votre cotisation dans un d?lai raisonnable et nous nous tenons dans l\'intervalle ? votre enti?re disposition pour toute question y relative.';

// OPEN FORM 44 AND POPULATE THE FIELDS
window.open('http://www.webamazingapps.com/projects/xxx/index.php/gestion-membres-2/suivi-administratif/gestion-courriers-rappel/creer-un-courrier-rappel-sa?xxx_fabrik_user_reminder___bloc_destinataire=' + email + '&gprh_fabrik_user_reminder___type_rappel=' + type + '&gprh_fabrik_user_reminder___no_rappel=' + no + '&gprh_fabrik_user_reminder___userid=' + userid + '&gprh_fabrik_user_reminder___cp_name=' + name + '&gprh_fabrik_user_reminder___cp_firstname=' + firstname + '&gprh_fabrik_user_reminder___cp_address_1=' + address_1 + '&gprh_fabrik_user_reminder___cp_address_2=' + address_2 + '&gprh_fabrik_user_reminder___cp_zip=' + zip + '&gprh_fabrik_user_reminder___cp_city=' + city + '&gprh_fabrik_user_reminder___bloc_introduction_co1=' + bloc_introduction_co1 + '&gprh_fabrik_user_reminder___bloc_situation_co1=' + bloc_situation_co1_1 + '&gprh_fabrik_user_reminder___bloc_attentes_co1=' + bloc_attentes_co1_1);
   };

Call this function from a 'click' event in the Javascript settings of the button element, pass 'this' as a parameter ...

Code:
inheritF59ToF44co1(this);
 
Last edited:
Update

To pass a database join value and populate a database join into another form :

Code:
  var country = form.formElements.get('gprh_fabrik_user_registration___cp_country').getValue();

and pass the raw value into the url :

Code:
window.open('http://www.webamazingapps.com/projects/gprh.ch/index.php/gestion-membres-2/suivi-administratif/gestion-courriers-rappel/creer-un-courrier-rappel-sa?gprh_fabrik_user_reminder___cp_country_raw=' + country);
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top