Гость
11 Сен 2013 11:54

I don't believe Cobalt can currently do this, but it would be nice to have conditional showing of fields. If someone click 'Yes' for a specific boolean field then an additional 2 fields appear for them to fill out. Or if someone selects 'Option 2' for this field than another field appears.

As I create more complex Types with Cobalt I believe this would be a handy feature for users entering content.

Последние изменения: 09 Июнь 2015


Sergey
Total posts: 13,748
25 Сен 2014 03:10

enocasino Parse error: syntax error, unexpected '$', expecting '&' or variable (T_VARIABLE) in /home/flyerfly/public_html/submissions/components/com_cobalt/views/form/tmpl/default_form_copyform.php on line 493

This is error in you PHP default_form_copyform.php. It is not about Javascript you inserted. YOu probably broke some PHP code.


narcis VIP
Total posts: 138
05 Июнь 2015 18:34

Hello there,

Thank you guys for this topic, it's exactly what i'm searching. I'd like set conditional fields to show field A or B if some entry is selected in boolean field, so i copied the code below in components/com_cobalt/views/form/tmpl/default_form_CUSTOM.php

(function($){
    $('input[name^=jform\\[fields\\]\\[10\\]]').on('change', function(){
        if(this.value == -1) {
           $('#filed-23').show();
           $('#filed-25').hide();
        } else {
           $('#filed-23').hide();
           $('#filed-25').show();
        }
    });
}(jQuery))

but it does not work. I also created default_form_CUSTOM.js and pasted code there, but does not work. Of course i replaced id by mines, and selected Custom template in type setting. Actually, i'm not sure about the place i must paste the code above in default_form_CUSTOM.php, i pasted in top, bottom, middle, but it's always petering out.

Help please.


Sergey
Total posts: 13,748
09 Июнь 2015 18:26

Check that your method is triggered by

(function($){
    $('input[name^=jform\\[fields\\]\\[10\\]]').on('change', function(){
        console.log(this.value);
    });
}(jQuery))

Please make sure this JS code is placed at the bottom of the form after field HTML is rendered.

If it does not work try to get to the field through ID.

try this also $(this).val() instead of this.value.

Работает на Cobalt