Important announcements from CouchCMS team
30 posts Page 3 of 3
@klaus, if checkboxes 4, 5 are not set as 'required' (i.e. the backend component is not really necessary), then a dedicated JS script could do the trick and also take care of the values upon clicking Save. You can ask me for that script. Also it may be wiser to exclude Conditionals from the problem itself, show all 3 checkboxes and upon clicking one of them - 'disable' the ones that need not be clicked. Making Conditionals work 'backwards' as you asked is not possible.
Free review of your code, Optimization, Help with Cart, Multilanguage, Datatables,.. anything - contact me!
Send a `Thank you!` [̲̅$̲̅(̲̅ ͡° ͜ʖ ͡°̲̅)̲̅$̲̅]
Couch+PHP [Couch Core PHP Q&A], HEPA [Help Pages]
Active topics [Forum posts from previous 7 days]
@trendoman
If you could cook something up with JS that would be most helpful, thank you very much! As you said yourself showing all three possibilities and than 'disable' the ones when another is clicked is exactly what I would like to achieve.
However the bunch of checkboxes are only a part of a larger survey and I would like to make use of the multi step form approach (viewtopic.php?f=2&t=7134&start=10#p9596). Would that still work?

But it is still intriguing if one could show/hide other parts of code as well (like a hint or an error message). Any advice on that?
But it is still intriguing if one could show/hide other parts of code as well (like a hint or an error message). Any advice on that?

There can be several ways of doing that.
For the backend and DBFs, the most straightforward would be to use a type 'message' editable region to create your hints or error messages. Since this is technically an editable region, it can be controlled through conditional logic like any other field e.g.
Code: Select all
<cms:func _into='my_cond' show_review=''>
    <cms:if "<cms:is 'Yes' in=show_review />">show<cms:else />hide</cms:if>
</cms:func>
<cms:editable type='message' name='msg' order='11' not_active=my_cond >
    <cms:show_warning heading='Important' >
        Please do not delete any of these pages!
    </cms:show_warning>
</cms:editable>

Tip: You can use <cms:show_info>, <cms:show_success>, <cms:show_error> or <cms:show_warning> to create your messages.

Coming to the original problem you had, I think you may try using the following -
you'll recall from the original post of this thread that we can use <cms:alt_js> to inject our own JS in the conditional function.

We can make use of it by placing a dummy type 'hidden' field *after* checkbox6 and making it dependent on the checkbox.
This way whenever checkbo6 is toggled, the hidden field's conditional function gets called. In this function, place your own JS to find and hide checkbox4 and 5 e.g.
Code: Select all
<cms:func _into='my_cond' checkbox6=''>
    hide
    <cms:alt_js>
        // place your JS code here to hide/show checkbox4 and 5
    </cms:alt_js>
</cms:func>
<cms:editable type='hidden' name='proxy' order='1000' required='1' not_active=my_cond>1</cms:editable>

Please try it and let me know if it helps.
I'm unfortunately at a loss here, as I basically know no JS at all. I tried to copy bits and pieces of the JS code of the "regular" conditions that get shown when looking at the sourcecode and tried a couple of google results but I must be missing something (knowledge of JS for sure :D ). It would be awesome to get a hand with this part as well, if not I'll work around it and simply have an error message shown with the next step of the form.
It would be awesome to get a hand with this part as well

OK :)
Here is some working code for you. I hope you are able to adapt it for your use-case
Code: Select all
<cms:editable name='checkbox4' type='checkbox' opt_values='yes' />
<cms:editable name='checkbox5' type='checkbox' opt_values='ok' />
   
<cms:func _into='my_cond' checkbox4='' checkbox5=''>
    <cms:if "<cms:is 'yes' in=checkbox4 />" || "<cms:is 'ok' in=checkbox5 />">hide<cms:else />show</cms:if>
</cms:func>   
<cms:editable name='checkbox6' type='checkbox' opt_values='nope' not_active=my_cond /> 

<cms:func _into='my_cond' checkbox6=''>
    hide
    <cms:alt_js>
        var $check4 = $form.find("div#k_element_checkbox4");
        var $check5 = $form.find("div#k_element_checkbox5");
       
        if($.inArray('nope', checkbox6)!=-1){
            $check4.hide();
            $check5.hide();
        }
        else{
            $check4.show();
            $check5.show();
        }

        return 1; //this dummy field is always hidden
    </cms:alt_js>
</cms:func>
<cms:editable type='hidden' name='proxy' order='1000' required='1' not_active=my_cond>1</cms:editable>

Hope it helps.
I'm much obliged! Works like a charm.

And if I may be so frank and ask for another solution I'd repay the favour with buying another commercial license :).

If it's somehow possible to check the value in a text input (non negative integer) and act on this like the following that would wrap up the problematic points for me on the current project:
Code: Select all
<cms:input name="temperature_at_zero" type='text'/>

<!-- if temperature <= 10 show this -->
<cms:input name="temperature_lt_10" type='text'/>
<!-- if temperature <= 20 show this as well -->
<cms:input name="temperature_lt_20" type='text'/>

etc.

If not I could fall back on a predifined set of temperatures in a dropdown to get the other fields, but would need to have an input field for 'temperature_at_zero' nevertheless. Would be cleaner if I could do it directly only with one input for it.
I'm setting up another template with conditional fields, for the backend only. The conditions work as they should, meaning they show and hide fields. However when saving the template no input in the depending fields gets saved - they remain simply blank. Anything I missed? Do I need to edit content_form.html for the specific template to make the saving happen?

Code: Select all
<cms:template title='Jobs' order='-10' clonable='1' dynamic_folders='1' parent='_development_'>

<cms:config_list_view exclude='default-page-for-project-php-please-change-this-title' searchable='1'>
    <cms:field 'k_selector_checkbox' />
    <cms:field 'k_page_title' />
    <cms:field 'k_page_foldertitle' />
    <cms:field 'k_page_date' />
    <cms:field 'k_actions' />   
</cms:config_list_view>

<cms:config_form_view>
   <cms:html>
        <cms:show_info heading='' >
            The page's title should only contain the job's title/position's description.
        </cms:show_info>
    </cms:html>
</cms:config_form_view>

<cms:editable name='meta_info' label='Meta Info' desc='for search engines' type='group' collapsed='1'>

   <cms:editable
      name='job_keywords'
      label='Keywords'
      desc='Enter content here'
      type='text'
      order='-80'
      />
      
   <cms:editable
      name='job_description'
      label='Meta description'
      desc='Enter content here'
      type='textarea'
      order='-70'
      />
   
</cms:editable>
   
<cms:editable
   name='job_expiration_date'
   label='Expiration date'
   desc='of displaying position on the website'
   type='datetime'
   />
   
<cms:editable
   type='radio'
   name='job_is_at'
   label='Position offered by Corporate Member or external'
   opt_values='Corporate Member=cm | External=ext'
   opt_selected='cm'
    />
   
   <cms:func _into='my_cond' job_is_at=''>
        <cms:if "<cms:is 'cm' in=job_is_at />">
            show
        <cms:else />
            hide
        </cms:if>
    </cms:func>
   
<cms:editable
   type='relation'
   label="Select company"
   desc=""
   name='job_with_cm'
   masterpage='corpmembers.php'
   has='one'
   not_active=my_cond
   />
   
   <cms:func _into='my_cond' job_is_at=''>
        <cms:if "<cms:is 'ext' in=job_is_at />">
            show
        <cms:else />
            hide
        </cms:if>
    </cms:func>
   
<cms:editable
   name='job_company_name'
   label='Company name'
   desc=''
   type='text'
   not_active=my_cond
   />
   
<cms:editable
   name='job_company_url'
   label='Company Website'
   desc='FULL URL! Best copy from browser window'
   type='text'
   not_active=my_cond
   />
   
<cms:editable
   name='job_url'
   label='Link to job application'
   desc='FULL URL! Best copy from browser window'
   type='text'
   />
   
<cms:editable
   name='job_content'
   label='Main Content'
   desc='Enter content here'
   type='richtext'
   />
   
<cms:editable name='downloads' label='Downloads' desc='' type='group' collapsed='1'>
   
   <cms:repeatable name='job_downloads' label='Downloadable files' stacked_layout='1'>
      <cms:editable name='job_downloads_title' label='Title' type='text' />
      <cms:editable name='job_downloads_file' label='File' type='file' />
   </cms:repeatable>

</cms:editable>
   
<cms:editable
   type='checkbox'
   name='job_news_already_published'
   label='News already published?'
   desc='Do not change this value unless you want to advertise the position again'
   opt_values='Yes'
   />
   
   <cms:func _into='my_cond' job_news_already_published=''>
        <cms:if job_news_already_published='Yes'>
            hide
        <cms:else />
            show
        </cms:if>
    </cms:func>
   
<cms:editable
   type='radio'
   name='job_add_news'
   label='Any previous employment experience?'
   opt_values='Do nothing=0 | Add default news=1 | Add custom news=2'
   opt_selected='0'
   not_active=my_cond
    />
   
   <cms:func _into='my_cond' job_add_news='' job_news_already_published=''>
        <cms:if "<cms:is '2' in=job_add_news />"
            &&
            job_news_already_published!='Yes'
        >
            show
        <cms:else />
            hide
        </cms:if>
    </cms:func>

<cms:editable name='create_news' label='Create News' desc='' type='group' not_active=my_cond>

   <cms:editable
      name='news_content'
      label='Content'
      desc='Enter content here'
      type='richtext'
      not_active=my_cond      
      />

</cms:editable>
</cms:template>
@klaus, wrong handling of radio-based conditional. Radios have only one value.
Free review of your code, Optimization, Help with Cart, Multilanguage, Datatables,.. anything - contact me!
Send a `Thank you!` [̲̅$̲̅(̲̅ ͡° ͜ʖ ͡°̲̅)̲̅$̲̅]
Couch+PHP [Couch Core PHP Q&A], HEPA [Help Pages]
Active topics [Forum posts from previous 7 days]
Spasibo, Trendoman!

In my simple mind I would have thought that a regular variable would have been the same as an array with just one value ;).
It could've.., maybe @KK will see it.

The community can mod <cms:is> tag to work for both cases, though.
Free review of your code, Optimization, Help with Cart, Multilanguage, Datatables,.. anything - contact me!
Send a `Thank you!` [̲̅$̲̅(̲̅ ͡° ͜ʖ ͡°̲̅)̲̅$̲̅]
Couch+PHP [Couch Core PHP Q&A], HEPA [Help Pages]
Active topics [Forum posts from previous 7 days]
30 posts Page 3 of 3

Who is online

In total there is 1 user online :: 0 registered, 0 hidden and 1 guest
(based on users active over the past 5 minutes)

Users browsing this forum: No registered users and 1 guest