Important announcements from CouchCMS team
42 posts Page 4 of 5
KK, is there a solution to following?

Controlling field is a checkbox. When superadmin clicked 'Yes' 2 other fields are conditionally displayed.
Superadmin is logging out. Admin logs in.
Admin must not be able to change controlling checkbox. Admin can only edit and save 2 visible conditional fields.
Admin must not see controlling field hidden via CSS, because it can not be changed by Admin.


Code: Select all
<cms:editable
    type='checkbox'
    name='has_usage_limit'
    label='Limit maximum applications?'
    opt_values='Yes'
    not_active=my_cond_test
/>

<cms:func _into='my_cond' has_usage_limit=''>
    <cms:if "<cms:is 'Yes' in=has_usage_limit />">show<cms:else />hide</cms:if>
</cms:func>

<cms:editable
     name='maximum_applications'
     label='How many times the Coupon can be used'
     desc='Completely disable Coupon by un-publishing this page'
     type='text'
     search_type='integer'
     validator='non_zero_integer'
     width='155'
     not_active=my_cond
/>


<cms:editable
     name='applications'
     label='How many times'
     type='checkbox'
     opt_values='Yes'
     not_active=my_cond
/>


I think this question can pop up some day. I have come to this quiz myself after experiments and don't yet have a solution.
Greetings!

I was working with Conditional Fields and have a doubt.

I have a dropdown "Delivery Parking".
If Delivery parking is "Yes"
Then, Show Delivery parking type editable and a check box (an editable) to confirm it is marked on the map
If confirmation is marked "Yes" show Leasing Office editable
Else if Delivery Parking is "No"
Then show Leasing Office editable

Can the else part be achieved? If yes then how?

Regards,
GenXCoders (Priya)
Image
where innovation meets technology
Hi,

Code: Select all
If Delivery parking is "Yes"
    Then, Show Delivery parking type editable and a check box (an editable) to confirm it is marked on the map
    If confirmation is marked "Yes"
        Then show Leasing Office editable
Else if Delivery Parking is "No"
    Then show Leasing Office editable

I think the 'Leasing Office editable' is the region that is bothering you.
From the pseudo-code above, following could be the logic (again, pseudo) attached to the region -
Code: Select all
If (Delivery Parking is "No") || (Delivery parking is "Yes" && confirmation is "Yes") 
    show
Else
    hide
End If

Hope this helps.
@KK Sir,
Thanks for the quick reply.

Yes Sir, The Leasing Office editable is bothering me because it needs to be shown in either condition, only that the condition needs to be marked before showing it. Also, if the condition is YES then Leasing Office editable needs to be shown only if Confirmation is also YES

My actual Code is:
Code: Select all
<!-- Part #1 -->
<cms:editable name="delivery_parking" label="Delivery Parking" type="dropdown" opt_values="Select =- | Yes | No" group="sow" required="1" not_active=cond_map_link_marking order="5" />
<cms:func _into='cond_delivery_parking' delivery_parking=''>
    <cms:if "<cms:is 'Yes' in=delivery_parking />">
        show
    <cms:else />
        hide
    </cms:if>
</cms:func>

<!-- Part #2 -->
<cms:editable name="delivery_parking_type" label="Delivery Parking Type" type="dropdown" opt_values="Select=- | Building wise | Common Parking | No Restriction | Specific Building" opt_selected="" group="sow" opt_selected="-" required="1" not_active=cond_delivery_parking order="6" />
<cms:editable type='checkbox' name='delivery_parking_type_marking' label='Delivery parking type marked on Map?' opt_values='Yes' order="4" required="1" not_active=cond_delivery_parking />
<cms:func _into='cond_delivery_parking_type_marking' delivery_parking_type_marking=''>
    <cms:if "<cms:is 'Yes' in=delivery_parking_type_marking />">
   show
    <cms:else />
   hide
    </cms:if>
</cms:func>

<!-- Part #3 -->
<cms:editable name="leasing_office" label="Leasing Office" type="dropdown" opt_values="Select =- | Yes | No" required="1" not_active=cond_delivery_parking_type_marking  />


Now what happens is that if i use checkbox for the "delivery_parking" editable, i get output but if i use dropdown i dont get any output.

An what I want to achieve is that:
If Part #1 is YES, show Part #2 and Part #3
Else If Part #1 is NO, show Part #3.
Image
where innovation meets technology
I had tried to provide a solution using pseudo-code.
Following is the same code in the form understood by Couch -
Code: Select all
    <!-- Part #1 -->
    <cms:editable name="delivery_parking" label="Delivery Parking" type="dropdown" opt_values="Select =- | Yes | No" group="sow" required="1" order="1" />


    <!-- Part #2 -->
    <cms:func _into='cond_delivery_parking' delivery_parking=''>
        <cms:if delivery_parking = 'Yes'>
            show
        <cms:else />
            hide
        </cms:if>
    </cms:func>
    <cms:editable name="delivery_parking_type" label="Delivery Parking Type" type="dropdown" opt_values="Select=- | Building wise | Common Parking | No Restriction | Specific Building" opt_selected="" group="sow" opt_selected="-" required="1" not_active=cond_delivery_parking order="2" />
    <cms:editable type='checkbox' name='delivery_parking_type_marking' label='Delivery parking type marked on Map?' opt_values='Yes' order="3" required="0" not_active=cond_delivery_parking />
   
    <!-- Part #3 -->
    <cms:func _into='cond_delivery_parking_type_marking' delivery_parking='' delivery_parking_type_marking=''>
        <cms:if delivery_parking = 'No' || (delivery_parking = 'Yes' && "<cms:is 'Yes' in=delivery_parking_type_marking />")>
            show
        <cms:else />
            hide
        </cms:if>
    </cms:func>
    <cms:editable name="leasing_office" label="Leasing Office" type="dropdown" opt_values="Select =- | Yes | No" required="1" order="4" not_active=cond_delivery_parking_type_marking  />

The 'order' of the regions needed to be tweaked as Couch expects all dependent regions to be physically situated *after* the controlling regions.

Also note that the "<cms:is" tag is required only for type 'checkbox' (type 'dropdown' can be checked using "=").

Hope this helps.
@KK Sir,

Also note that the "<cms:is" tag is required only for type 'checkbox' (type 'dropdown' can be checked using "=").

I was not aware about this.

Your sample code as always has helped me.

But I have now come to another issue:
Code: Select all
<cms:editable name="access_type" label="Access Type" type="dropdown" opt_values="Select =- | Blank=0 | Delivery=1 | Private=2" not_active=cond_num_of_entrances_marking group="sow" order="16" />
      <cms:func _into="cond_access_type" access_type=''>
         <cms:if (access_type != '0' && (access_type = '1' || access_type = '2'))>
            show
         <cms:else />
            hide
         </cms:if>
      </cms:func>

      <cms:editable name="gate" label="Gate" type="checkbox" opt_values="Yes" not_active=cond_access_type group="sow" order="17" />
      <cms:func _into="cond_gate" gate=''>
         <cms:if "<cms:is 'Yes' in=gate />" >
            show
         <cms:else />
            hide
         </cms:if>
      </cms:func>

      <cms:editable name="num_of_gates" label="Number of Gates" type="dropdown" opt_values="Select =- | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30" not_active=cond_gate group="sow" order="18" />
      <cms:func _into="cond_num_of_gates" num_of_gates=''>
         <cms:if num_of_gates ne '-'>
            show
         <cms:else />
            hide
         </cms:if>
      </cms:func>

      <cms:editable name="gate_type" label="Gate Type" type="dropdown" opt_values="Select =- | Gate | Lift Gate | Sliding Gate | Bollard" not_active=cond_num_of_gates group="sow" order="19" />
      <cms:func _into="cond_gate_type" access_type='' gate_type=''>
         <cms:if access_type = '0' || gate_type ne '-'>
            show
         <cms:else />
            hide
         </cms:if>
      </cms:func>

      <cms:editable name="locked_gate" label="Locked Gate" type="dropdown" opt_values="Select =- | Yes | No" not_active=cond_gate_type group="sow" order="20" />


Here, 'access_type' has values "Select =- | Blank=0 | Delivery=1 | Private=2".
I am trying to show 'locked_gate' if the access_type='0' (This does not work).
While on the other hand, if access_type='1' or access_type='2' I want to show "gate, num_of_gates, gate_type" (This Works)

How can I achieve this: I am trying to show 'locked_gate' if the access_type='0'?

Could you please guide me sir!

Regards,
GenXCoders
Image
where innovation meets technology
@KK Sir,
I found the issue. The div with the k_element_<editable_name> was misplaced by me, hence I was facing the issue.
Regards,
GenXCoders
Image
where innovation meets technology
EDIT: [SOLVED]
The conditional field js was not available on the edit_view since I had the k_matched_route set only for the create_view. I added the route condition for edit_view and the conditional field js to become available for the edit_view and ence the expected output is generated.

Good Evening All!

I am using conditional fields with DBF with the Custom Route Addon.
In the create_view the conditionally fields are hidden. But in the edit_view the conditional fields are not hidden.

How to hide conditional fields in the edit_view?

Regards,
GenXCoders
Image
where innovation meets technology
@genxcoders, please PM me the (relevant) code and I'll try to see what is going wrong.
Greetings to All!

Is it possible to have editable of type=relation with has=one attribute to work with conditional fields?
For example:
Code: Select all
<cms:editable name='personal_details_marriage' label='Marital Status' type='relation' masterpage='users/marital-status/index.php' has="one" order='3' />
<cms:func _into='cond_marital_status' personal_details_marriage=''>
    <cms:if personal_details_marriage eq 'Married'>
        show
    <cms:else />
        hide
    </cms:if>
</cms:func>
<cms:editable name='personal_details_doa' label='Date of Anniversary' type='datetime' show_labels='0' not_active=cond_marital_status order='5' />

I have more complex fields as below, but the issue is that the dropdown values are all hard coded, can these work dynamically too?
Code: Select all
<cms:editable name='job_details' label='User Details' type='group' order='5' />
        <cms:editable name='job_row' type='row' group='job_details' order='1'>
            <cms:editable name='job_details_usertype' label='User Type' type='relation' masterpage='users/user-type/index.php' has="one" class='col-md-12' order='1' />

            <cms:func _into="cond_usertype" job_details_usertype=''>
                <cms:if (job_details_usertype eq 'Accounts') || (job_details_usertype eq 'Collection Center') || (job_details_usertype eq 'Driver') || (job_details_usertype eq 'Farmer') || (job_details_usertype eq 'Plant')>
                    show
                <cms:else />
                    hide
                </cms:if>
            </cms:func>
            <cms:editable name='job_details_uid' label='Unique Id' type='text' class='col-md-12' begin_from='1' min_length='5' not_active=cond_usertype order='1' />

            <cms:func _into="cond_usertype_driver" job_details_usertype=''>
                <cms:if job_details_usertype eq 'Driver'>
                    show
                <cms:else />
                    hide
                </cms:if>
            </cms:func>
            <cms:editable name='identity_details_driving_license' label='Driving License' desc='Image Size: W:250px H: 250px | Image shape rectangular | For driver(s)' type='securefile' show_preview='1' preview_width='100' allowed_ext='jpg,jpeg,png,bmp' class='col-md-12' order='2' not_active=cond_usertype_driver />

            <cms:func _into="cond_usertype_allocatedcc" job_details_usertype=''>
                <cms:if (job_details_usertype eq 'Farmer') || (job_details_usertype eq 'Collection Center')>
                    show
                <cms:else />
                    hide
                </cms:if>
            </cms:func>
            <cms:editable name='job_details_center' label='Allocated Collection Center' type='relation' masterpage='users/collection-center/index.php' has="one" class='col-md-12' order='3' not_active=cond_usertype_allocatedcc />
            <cms:ignore>
            <cms:editable name='job_details_center' label='Allocated Collection Center' type='relation' masterpage='users/collection-center/index.php' has="one" class='col-md-12' order='3' not_active=cond_usertype_allocatedcc />
            </cms:ignore>

            <cms:func _into="cond_usertype_banking" job_details_usertype=''>
                <cms:if (job_details_usertype eq 'Farmer')>
                    show
                <cms:else />
                    hide
                </cms:if>
            </cms:func>
            <cms:editable name='job_details_bank_passbook' label='Passbook First Page Image' type='securefile' show_preview='1' preview_width='100' class='col-md-12' allowed_ext='jpg,jpeg,png,bmp' order='4' not_active=cond_usertype_banking />
            <cms:editable name='job_details_bank' label='Bank Name' type='relation' masterpage='users/bank/index.php' has="one" class='col-md-3' order='5' not_active=cond_usertype_banking />
            <cms:editable name='job_details_bank_branch' label='Bank Branch' type='text' class='col-md-3' order='6' not_active=cond_usertype_banking />
            <cms:editable name='job_details_bank_branch_ifsc' label='IFSC Code' type='text' class='col-md-3' validator='exact_len=11 | alpha_num' order='7' not_active=cond_usertype_banking />
            <cms:editable name='job_details_bank_account' label='Account Number' type='text' class='col-md-3' order='8' not_active=cond_usertype_banking />

        </cms:editable>


I n the above code all conditional fields are dependent on job_details_usertype editable. Now usertype, as defined now is set to driver, owner, plant, etc. Each of the usertype actually controls the type of data they will be shown and their interaction with it. This is to implement a user access type web app for milk collection system. Is there a better way to implement a user role based access?

If there is a possibility it would be great. I earlier was using type=dropdown, but then when a user adds a new value which is in relation then it will need to be added separately to the dropdown editable. Also, if I have dropdown type i am unable to access the value in edit_views.

Any help or input would be great. If relation and conditional field do not work together, what can be the best work around?

Regards,
GenXCoders (Aashish)
Image
where innovation meets technology
42 posts Page 4 of 5