Validation help

zorzis

Member
hello,
i have 3 elemets as seen below in a repeated join group.
the first one: Family is a databasejoin element
the second one: Algae is a cascade dropdown watching Family element
and the third one: Quantity is a field element

i want when no select has been done to Family and ofcourse Algae (as if no select from the Family means no select to Algae too), then someone cannot enter any value to Quantity and if yes to show the validation error(ajax is set to yes).

But if no selection is made to can record the empty value (0).

also when Family dropdown is selected to a value, then Algae to cannot left empty.



any idea?
 

Attachments

  • Untitled.jpg
    Untitled.jpg
    66.9 KB · Views: 261
hi
you would need to do this with some custom js code. So say your form's id is 1 you need to create a js file in components/com_fabrik/js/form_1.js (replace the '1' with the form's id)

Then copy this into it:

Code:
// Enter the full element name of cdd element
var cdd = 'regons___country_id';

// Enter the full element name of the field that should be disabled if nothing selected for the cdd element
var fld = 'regons___street';

//////////////////////////////////////////////////////////////////////////////////////
// Leave this code as it is:
//////////////////////////////////////////////////////////////////////////////////////
window.addEvent('domready', function () {
    
    document.getElements('select[name*=' + cdd + ']').each(function (target) {
            setReadOnly(target);
    });
    
    Fabrik.addEvent('fabrik.form.group.duplicate.end', function () {
        document.getElements('select[name*=' + cdd + ']').each(function (target) {
            setReadOnly(target);
    });
    });
    document.addEvent('change:relay(select[name*=' + cdd + '])', function (e, target) {
        setReadOnly(target);
    });
});

function setReadOnly(target) {
    var subGroup = target.getParent('.fabrikSubGroupElements');
    var field = subGroup.getElement('input[name*=' + fld + ']');
    if (target.get('value') === '') {
        field.value = '';
        field.set('readonly', 'readonly');
        field.addClass('readonly');
    } else {
        field.set('readonly','');
        field.removeClass('readonly');
    }
}
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top