Is it possible to use variable.value to setValue() on:click action

I have a button that I need to make dynamic and I have two questions.

  1. Can I use variable_name.value to setValue() such as variable_name.value.setValue()? (starting to think I can’t)
  2. If it is possible what is the correct syntax?

Basically I have the below on:click action (which works) on a button and I have a variable (var_contact_target) that gets set to a value of ‘modal_detail_inspection.form_detail_inspection.inp_agreed_to_by’ when another button is clicked.

dmx- on:click=“modal_detail_inspection.form_detail_inspection.inp_agreed_to_by.setValue(contact_id);modal_ detail_inspection.form_detail_inspection.inp_agreed_to_by_text.setValue(Contact_Name);modal_contacts.hide()”

My instinct was to do:

on:click=“var_contact_target.value.setValue(contact_id);var_contact_target.value+’_text’.setValue(Contact_Name);modal_contacts.hide()”

OR

on:click="{{var_contact_target.value}}.setValue(contact_id);{{var_contact_target.value}}+’_text’.setValue(Contact_Name);modal_contacts.hide()"

Neither var_contact_target.value nor {{var_contact_target.value}} get replaced with the value.

I know the variable is set correctly because I can put {{var_contact_target.value}} in the button label/html and it displays correctly in the button label.

Is this possible? Seems like a variable’s value should be available for use like this in dynamic events. Hopefully I’m missing something simple.

Thanks in advance.

I’m not sure I understand what are you trying to achieve exactly. Do you want to set a value of a variable on click?

Thanks for the reply @Teodor.

I know how to set variables on click. The variable gets set correctly cause I can display the value of it in the button text that is supposed to use it on click.

Here is the use case. I have created a contact “lookup” field and made it a server include file to make it dynamic so I don’t have to recreate it for each instance I need it. I simply include the file and set some PHP variables before the included file that the include is expecting for each instance it’s used. Here is how two different fields get set in the same modal form.

<?php $input_name = 'agreed_to_by'; $target_input = 'modal_detail_inspection.form_detail_inspection.inp_'.$input_name; ?><?php include 'inc/contact_lookup_field.php'; ?>
<?php $input_name = 'representative_for'; $target_input = 'modal_detail_inspection.form_detail_inspection.inp_'.$input_name; ?><?php include 'inc/contact_lookup_field.php'; ?>

When the user clicks on the “Search” icon for instance, I set the app connect variable called var_contact_target to whatever is set to that input’s $target_input php variable.

dmx-on:click=“modal_contacts. var_contact_target.setValue(’<?php echo $target_input; ?>’);modal_contacts.show()”

In the Contacts modal that appears the user can search for a contact. The checkmark button for each contact should read the var_contact_target variable in it’s on click so that when a user clicks the checkmark button it selects that contact and fills in the visible input with the contact_name and a hidden field with the contact_id. It knows which inputs to fill in based on what is set in the var_contact_target variable.

If I hard coded the check mark button it would look like this for the ‘agreed_to_by’ field:

dmx-on:click=“modal_detail_inspection.form_detail_inspection.inp_agreed_to_by.setValue(contact_id);modal_detail_inspection.form_detail_inspection.inp_agreed_to_by_text.setValue(Contact_Name);modal_contacts.hide()”

I’m trying to use an app connect variable as I would any php variable. For example, if I set a $_GET parameter instead of the app connect variable to the $target_input value of modal_detail_inspection.form_detail_inspection.inp_agreed_to_by for the agreed_to_by input I would use php on the button click like so and it would work:

dmx-on:click="<?php echo $_GET['var_contact_target'];?>.setValue(contact_id);<?php echo $_GET['var_contact_target'].'_text';?>.setValue(Contact_Name);modal_contacts.hide()"

This works because once the php is parsed the on:click looks the same as if I had hardcoded it:

dmx-on:click=“modal_detail_inspection.form_detail_inspection.inp_agreed_to_by.setValue(contact_id);modal_detail_inspection.form_detail_inspection.inp_agreed_to_by_text.setValue(Contact_Name);modal_contacts.hide()”

I was hoping that a var_contact_target created as an app connect variable would get parsed in a similar way.

Hope that all makes sense. :upside_down_face:

Sport but I don’t think I’m following.
I got lost in your explanation and can’t understand your idea. I have a feeling you are probably trying to do something in a more complicated way than it should be done.

It’s ok I’ll figure it out. I’m basically doing a autocomplete type field on steroids haha. I’m an old school php hand coder so I’m still getting used to using a UI and sometimes revert to coding if I’m in a hurry.

Appreciate you taking the time to check this post.

I guess this is about your hidden fields in your form again

It’s really easy, just select dynamic event you want to use (say modal close) , select the input, select set value and enter a value. No code needed just a few clicks

same for variables

We need a TL;DR :slight_smile:

Are you trying to set a PHP variable value with the App Connect function setValue()?

Thanks @Hyperbytes it’s not about the hidden fields and perhaps I’m not doing a great job of explaining. I can see that everyone is confused about it…haha

I’ll figure it out.

Hey, @JonL, no I guess to break it down in it’s simplest form (and I’m starting to think it can’t be done with the variable.value) is let’s say I set a variable on button click like so:

var_contact_target.setValue('modal_detail_inspection.form_detail_inspection.inp_agreed_by');

So now variable var_contact_target has a value = modal_detail_inspection.form_detail_inspection.inp_agreed_by and if I were to put {{var_contact_target.value}} or in some places var_contact_target.value on my page it would render out modal_detail_inspection.form_detail_inspection.inp_agreed_by

If I want to set the value of an input I would use something like:
modal_detail_inspection.form_detail_inspection.inp_agreed_by.setValue(‘foo’);
Now the input with id ‘inp_agreed_by’ has a value of foo.
Since my code will be reusable for multiple inputs I won’t always know this portion…

modal_detail_inspection.form_detail_inspection.inp_agreed_by

…of

modal_detail_inspection.form_detail_inspection.inp_agreed_by.setValue('foo'); 

and I need it to be dynamic which I had hoped to use the var_contact_target variable’s value which is currently set to ‘modal_detail_inspection.form_detail_inspection.inp_agreed_by’ as that portion of the .setValue(‘foo’) thinking that when this:

var_contact_target.value.setValue('foo');   or  {{var_contact_target.value}}.setValue('foo');

got parsed it would actually render as:

modal_detail_inspection.form_detail_inspection.inp_agreed_by.setValue('foo'); 

but it does not they render the same way there looked in code view:

var_contact_target.value.setValue('foo');   or  {{var_contact_target.value}}.setValue('foo');

I had hope it would function similar to what I’m used to in php:

<?php $var_contact_target = 'modal_detail_inspection.form_detail_inspection.inp_agreed_by';?>

This

<?php echo $var_contact_target;?>.setValue('foo');

Would render as this in the browser:

modal_detail_inspection.form_detail_inspection.inp_agreed_by.setValue('foo');

Hope that makes more sense?

I think I get you. You are describing pointers.
App Connect is a js library and js doesn’t admit variables referencing other variables.

In JS only Objects and Arrays can be assigned by reference.

1 Like

Thanks @JonL I was suspecting so but I was hoping there was a Wappler secret I was missing. I’ll just use a $_GET variable which is working but doing strange things and had hope the js variable would be more predictable.

Thanks for all the replies guys.

1 Like