Update element if another is not empty

thewedge

New Member
I made a function and added it to my form js file.

function emailreport(el) {
var element1 = Fabrik.getBlock('form_9').formElements.get('dfsb8_logs___issue_report');
if (element1 !== '') {
el.update("1");
}
}

Then I added
emailreport(this);

to the javascript of the element I want to add 1 to and used on load, but element doesn't render 1 in source.
 
Use something like Chrome's dev tools, set a breakpoint on the first line in your function, and see what the variables get set to.

And if you are trying to get the value of issue_report, you need to use getValue() ...

Code:
var element1 = Fabrik.getBlock('form_9').formElements.get('dfsb8_logs___issue_report').getValue();

... and as a short cut, as you have the element object passed as an arg, which has the main form object as a property, you can do ...

Code:
var element1 = el.form.formElements.get('dfsb8_logs___issue_report').getValue();

... then you don't have to worry about the form ID, makes it easier copying and pasting code around between forms.

-- hugh
 
That worked thanks.

Rather than making another thread, what is the time popup style in when you do a date and time field. Is it bootstrap. I am finding when it is in my base template it breaks up and the x doesn't work to close it. When I am in the backend it performs correctly.
 
We use the (now deprecated) J! date picker.

Can't really help with that without seeing your site. Which I can't really do in Community support.

-- hugh
 
ok

I have one more thing. In my email plugin I have a condition. Before this update field the condition was

return '{dfsb8_logs___issue_report}' != "";

Which is still true
But after someone puts something into the field then the other filed is 1 and can't send a second notification as I have other emails to send out when other conditions are met with another field.

The other condition is

return '{dfsb8_logs___email_issue_report}' != "1";


I tried to do an if statement but I get an error: syntax error, unexpected '='

if('{dfsb8_logs___issue_report}' = ""){
return '{dfsb8_logs___issue_report}' != "";
}elseif('{dfsb8_logs___email_issue_report}' = "1"){
return '{dfsb8_logs___email_issue_report}' != "1";
}
 
That's because you have an unexpected =. :)

In PHP, = is an assignment operator. You assign a value to a variable with it, like $foo = 1.

So you are trying to assign the value "" to the literal string '{dfsb8_logs___issue_report}'.

For comparisons, use == or ===.

PHP:
if ('{dfsb8_logs___issue_report}' == "")
{
    return '{dfsb8_logs___issue_report}' != "";
}
else if('{dfsb8_logs___email_issue_report}' == "1")
{
    return '{dfsb8_logs___email_issue_report}' != "1";
}

-- hugh
 
For completeness, the difference between == and === is that the former is "loosely" typed, meaning strings and numbers are considered equal, so 1 == "1". The triple equals compares type as well, so 1 === "1" is not true.

Placeholders are always strings, unless you cast them yourself to another type. So '{foo___bar}' === '1' would work, but '{foo___bar}' === 1 would not, unless you did (int)'{foo___bar}') === 1.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top