ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Updating a relationship field with Safecracker and limited < options >

December 12, 2011 12:26pm

Subscribe [2]
  • #1 / Dec 12, 2011 12:26pm

    Werner Gusset

    122 posts

    I use safecracker and I want to edit a relationship field. How can I limit the options within the <select> to just a limited number of options?

    Usually we do this

    <label>The label:</label>
       {custom_fields}
         {if relationship}
           <select id="{our_field}" name="{our_field}">
             {options}
                <option value="{option_value}"{selected}>{option_name}</option>
            {/options}
           </select>
         {/if}
      {/custom_fields}

    And this will list all relationship entries in the dropdown and shows the selected. Perfect.

    Interesting enough, this would do the same

    {field:our_field}


    But for some reason I don’t want the user to be able to change the dropdown value. In this case I show the value of the relationship field and have the above code for the dropdown in a hidden div. Only this way I get the value written back into the db.

    But now I want to have only 3 dropdown values (out of 10) in the < select >. I know ways how to pick those with an embed. But there is no way to write the selected value in to the db then. I tried many ways.

    It seems that Safecracker only writes values into the db when we use the code like above. As soon as we construct a dropdown field “by hand” and want to bring the selected value into the db, we fail.

    I thought what is reported here is solved in 2.3.1. There is a bug report for 2.2.2 with a fix here. A fix we can not find incorporated in 2.3.1. If we insert it in 2.3.1 we still can not save a value from a self written <select>. Only the full Safecracker code like above will work.

    Can someone tell me how I would bring a selected value in a relationship field with a <select> that I limit, let’s say from 10 <options> to only 3? (The options limit according to the member level of the logged in member.

    Help would be appreciated.

     

  • #2 / Dec 13, 2011 12:03pm

    Kevin Smith

    4784 posts

    Hi Werner,

    The bug report you linked does have a solution, but it hasn’t been released yet. The status on the report says, “Fixing Right Away”, which means that we’ve fixed it, but it’s only fixed in our internal code. It’s not made its way into a release just yet.

    To answer the larger question here, SafeCracker doesn’t support customizing the field like you’d like to do. So it’s not a bug; it’s just not a supported feature. I would suggest instead that you might make a Feature Request to be able to limit the options SafeCracker gives in multi-select, dropdown, and checkbox field types.

    Does that help answer your question?

  • #3 / Dec 13, 2011 12:57pm

    Werner Gusset

    122 posts

    Thanks Kevin

    Yes my question is answered. I will make a Feature Request these days.

  • #4 / Dec 14, 2011 3:41am

    Kevin Smith

    4784 posts

    Sounds good, Werner. Let me know if there’s anything else I can do to help.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases