How to use 'code' field in javaScript tab

TStip

New Member
I have tried the following:

Form: testformulier
Group: testgroep
Element1: waarde1 (plugin = field default = 0)
Element2: waarde2 (plugin = field default = 0)
Element3: bestand (fileupload plugin)

At waarde1 I used these settings in JavaScript tab:

Action = Load
Published = Yes
code =

if ($('testformulier___waarde1').get('value') == 0) and ($('testformulier___waarde2').get('value') == 0)
{
$('testformulier___bestand').hide();
}
else
{
$('testformulier___bestand').show();
}

If this works, I would also add this to the action = change

But when I now open a new form, with waarde1=0 and waarde2=0, bestand (element3) remains visible.

What am I doing wrong?
Thanks in advance ...
 

Attachments

  • javascript_tab.png
    javascript_tab.png
    13.8 KB · Views: 368
I've read it, so now I have tried this:

var name1 = Fabrik.getBlock('testformulier').formElements.get('testformulier___waarde1');
var name2 = Fabrik.getBlock('testformulier').formElements.get('testformulier___waarde2');
var bestand = Fabrik.getBlock('testformulier').formElements.get('testformulier___bestand');
{
if name1.get('value') == 0 and name2.get('value') == 0
{
bestand.hide();
}
else
{
bestand.show();
}
}

But also no effect.
 
I think you could actually do this with the built in commands, i.e the various dropdowns below your current script.

Just a couple of pointers on your code though.

I believe, (unless things have changed), where you have Fabrik.getBlock('testformulier') needs to be the form id, Fabrik.getBlock('form_1'). So replace 1 with whatever you form id is.

The first and last curly bracket doesn't need to be there.
 
Hi felixcat,

I can't fix it with the built in commands because I need to check two fields (waarde1 AND waarde2 has to be 0)
My form id is 1, so I tried the code below now, but again no result.

var name1 = Fabrik.getBlock('form_1').formElements.get('testformulier___waarde1');
var name2 = Fabrik.getBlock('form_1').formElements.get('testformulier___waarde2');
var bestand = Fabrik.getBlock('form_1').formElements.get('testformulier___bestand');
if name1.get('value') == 0 and name2.get('value') == 0
{
bestand.hide();
}
else
{
bestand.show();
}
 
Okay I overlooked that point.

You may want to create a form JS file, there's a wiki page somewhere about this. I think is is nearer to what you want but I don't think this is going to cover all your requirements.

Code:
var name1 = Fabrik.getBlock('form_1').formElements.get('testformulier___waarde1');
var name2 = Fabrik.getBlock('form_1').formElements.get('testformulier___waarde2');
var bestand = Fabrik.getBlock('form_1').formElements.get('testformulier___bestand');
 
if ((name1.get('value') == 0) && (name2.get('value') == 0)) {
    bestand.hide();
} else {
    bestand.show();
}
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top