Coded something up in Couch in an interesting way? Have a snippet or shortcode to share? Post it here for the community to benefit.
24 posts Page 3 of 3
Can I change mode = 'create' instead of mode = 'edit'?
Code: Select all
    <cms:template clonable='1'>
        <cms:repeatable name='my_repeatable'>
            <cms:editable name='my_text' type='text' />
            <cms:editable name='my_checkbox' type='checkbox' opt_values='Newspaper || Website || Phone Book' />
            <cms:editable name='my_dropdown' type='dropdown' opt_values='Make a selection=- | Yes=2 | No=1' />
        </cms:repeatable>
    </cms:template>


    <cms:set submit_success="<cms:get_flash 'submit_success' />" />
    <cms:if submit_success >
        <h4>Saved.</h4>
    </cms:if>

    <cms:form
        masterpage=k_template_name
        mode='create'
        pafe_id=k_page_id
        enctype='multipart/form-data'
        method='post'
        anchor='0'
        >

        <cms:if k_success >
            <cms:capture into='my_data' is_json='1'>
                <cms:show_repeatable 'my_repeatable' as_json='1' />
            </cms:capture >
           
            <cms:capture into='my_data.' is_json='1'>
               {
                  "my_text" : <cms:escape_json><cms:show frm_my_text2 /></cms:escape_json>,
                  "my_checkbox" : <cms:escape_json><cms:show frm_my_checkbox2 /></cms:escape_json>,
                  "my_dropdown" : <cms:escape_json><cms:show frm_my_dropdown2 /></cms:escape_json>
               }
            </cms:capture >

            <cms:db_persist_form
                _invalidate_cache='0'
                _auto_title='1'
                my_repeatable=my_data
            />

            <cms:if k_success >
                <cms:set_flash name='submit_success' value='1' />
                <cms:redirect k_page_link />
            </cms:if>
        </cms:if>

        <cms:if k_error >
            <div class="error">
                <cms:each k_error >
                    <br><cms:show item />
                </cms:each>
            </div>
        </cms:if>

        <!--
            bound inputs can be placed here
        -->
        <cms:input name='my_text2' type='text' /><br>
        <cms:input name='my_checkbox2' type='checkbox' opt_values='Newspaper || Website || Phone Book' /><br>
        <cms:input name='my_dropdown2' type='dropdown' opt_values='Make a selection=- | Yes=2 | No=1' /><br>

        <cms:input type='submit' name='submit' value='Submit' />
    </cms:form>   
Can I change mode = 'create' instead of mode = 'edit'?

I don't see any problem with that.
--
active topics, google
Free support is never free.. Donate!
@KK

I am exploring the path of setting RR's data dynamically from backend. Example use-case is occasionally pasting a huge json into a textarea field and voila - repeatable region is set without a ton of work.

Tag cms:persist is not reliable for this case - it saves only the first row, it demands only a variable name (rregion = my_data) and doesn't accept a json-encoded string as region's data (doesn't work as rregion = '[{"field":"data"}]' ).

I am using the following code for the demo template which illustrates the problems -
Code: Select all
<?php require_once( 'couch/cms.php' ); ?>
<cms:template clonable='1'>
    <cms:repeatable name='my_repeatable'>
        <cms:editable name='my_text' type='text' />
        <cms:editable name='my_text2' type='text' />
        <cms:editable name='my_checkbox' type='checkbox' opt_values='=1' />
    </cms:repeatable>
    <cms:editable type='textarea' name='log' label='Log' />
</cms:template>


<cms:config_form_view>
    <cms:persist
        dummy = "<cms:set my_persist_data = '[{"my_text":"578","my_text2":"","my_checkbox":"1"},{"my_text":"99","my_text2":"","my_checkbox":"1"}]' is_json='1' />
                 <cms:capture into='my_persist_data_log'>
Var 'my_persist_data' is set: <cms:show my_persist_data as_json='1' />.
Is array? <cms:is_array my_persist_data />.
Array cnt: <cms:arr_count my_persist_data />.
                 </cms:capture>"
        my_repeatable = my_persist_data
        log = my_persist_data_log
    />
</cms:config_form_view>
<?php COUCH::invoke(); ?>


Did I miss something or it is not possible to make cms:persist save repeatable region?

Thanks and regards
@ant
active topics, google
Free support is never free.. Donate!
24 posts Page 3 of 3

Who is online

In total there are 4 users online :: 0 registered, 0 hidden and 4 guests
(based on users active over the past 5 minutes)

Users browsing this forum: No registered users and 4 guests