Forum for discussing general topics related to Couch.
15 posts Page 2 of 2
@sterre, good to know this helped :)
I was browsing through some old code and Wow, how things elude us.. Actually, I had this solved via a custom validator (see Append uid to page name viewtopic.php?f=4&t=12651#p35649) and it was not difficult, yet needed some reading of KUID class for UID to update the value upon saving of a fresh (id='-1') page.
Code: Select all
$page->id = 0;  // KUID:get_data() hack
$page->creation_date = $FUNCS->get_current_desktop_time(); // KUID:shortcode_handler() hack


Nevertheless, saving twice is a neat approach that I'll be using forever in other tasks. :)
@KK, if the template in question has a "required" editable of type='relation', then it seems the field must be repeated again in the second-stage saving.

Code: Select all
    <cms:if k_cur_form_mode eq 'create'>
        <!-- find newly created page and edit it -->
        <cms:pages masterpage=k_template_name id=k_last_insert_id show_future_entries='1' limit='1'>
            <cms:db_persist
                _masterpage=k_template_name
                _mode='edit'
                _page_id=k_page_id

                k_page_name="<cms:show k_page_name />-xxx"
                k_page_title="<cms:show k_page_title /> xxx"
               
                required_relation_field = frm_required_relation_field
            />
        </cms:pages>
    </cms:if>


Without this amendement there'll be an error, such as this sample
Could not successfully run query: Duplicate entry '191-687-119' for key 'PRIMARY'
@trendoman, thanks for the heads-up.

I tested and, yes indeed, this was a problem - not only with a 'required' field but anytime something is selected into a relation field while creating a new page. The reason was that while saving the same page the second time, Couch used cached info from the last save.

I have pushed a new commit to GitHub trying to resolve this issue.
Please test it and let me know if it helps.

Thanks.
@KK, indeed that cache issue is resolved. I wonder if there is a similar cache issue with a dropdown field? In attached test.php I am always getting "Required field cannot be left empty" on a configured field.

test.php.zip
(594 Bytes) Downloaded 123 times


KK wrote: Please test it and let me know if it helps.

Thanks.
15 posts Page 2 of 2
cron