No pre-selected state for radio buttons
Posted: 13 January 2011 06:46 AM   [ Ignore ]
Is a Really Great Dancer
RankRank
Total Posts:  61
Joined  2010-12-03

I have a radio button field in my entry edit form with two options - ‘active’ and ‘inactive’ but when i add the {field:campaign_status} to my form neither button is checked even though one of the two options is set.

How can i show the selected option?

Profile
 
 
Posted: 13 January 2011 06:48 AM   [ Ignore ]   [ # 1 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

This is on an edit form?

Profile
 
 
Posted: 13 January 2011 06:56 AM   [ Ignore ]   [ # 2 ]
Is a Really Great Dancer
RankRank
Total Posts:  61
Joined  2010-12-03

Yes, well they are both the same template but the form becomes an edit form if segment_3 has an id

Profile
 
 
Posted: 13 January 2011 06:57 AM   [ Ignore ]   [ # 3 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

But you’re talking about a pre-selected state for an edit form, right? Or you want a pre-selected state on a new entry?

Profile
 
 
Posted: 13 January 2011 07:03 AM   [ Ignore ]   [ # 4 ]
Is a Really Great Dancer
RankRank
Total Posts:  61
Joined  2010-12-03

Well both really, I’d like it to default to the ‘inactive’ state on the create new entry form then when the user goes back to edit the entry it shows whatever state it was saved as last.

Profile
 
 
Posted: 13 January 2011 11:04 PM   [ Ignore ]   [ # 5 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

It should have the right one selected when you’re editing an entry. As for a new entry, I’m not sure there’s a good way to pre-select one, maybe you could use some javascript to accomplish that. You want to show me your template code?

Profile
 
 
Posted: 13 January 2011 11:22 PM   [ Ignore ]   [ # 6 ]
Is a Really Great Dancer
RankRank
Total Posts:  61
Joined  2010-12-03

Thanks, it turns out it wasn’t showing the right state in the edit screen because I was trying something silly to only show the field if the entry had related entries - see below. If i take the field out of the reverse_related entries lopp it works fine. You wouldn’t know an easy way of accomplishing that would you? grin
What sort of javascript would i need to set a default state on the create new entry form?

{exp:safecracker channel="campaigns" return="account/my-campaigns" error_handling="inline" entry_id='{segment_3}'}

<h2><span class="grey">Edit campaign:</span{title}</h2>
<
p>Edit your campaign details and assets, and make campaigns active or deactivate them here.</p>

<
div class="form">
     <
div class="error">
    
{if global_errors:count}
            
<ul>
            
{global_errors}
                
<li>{error}</li>
            
{/global_errors}
            
</ul>
        
{/if}
        {if field_errors
:count}
            
<ul>
            
{field_errors}
                
<li>{error}</li>
            
{/field_errors}
            
</ul>
        
{/if}
      
</div>
<
br class="clear" />
    <
fieldset>
        <
class="error">{error:title}</p>
        <
label>Campaign name:</label>
        <
input type="text" name="title" id="title" value="{title}"/></input>
        


        <
label>Campaign status:</label>
        
{exp:channel:entries status="open|featured" entry_id='{segment_3}' username="CURRENT_USER"}
            {reverse_related_entries limit
="1"
                {field
:campaign_status}
            {
/reverse_related_entries} 
        {
/exp:channel:entries}

        
        
<class="error">{error:campaign_desc}</p>
        <
label>Description:</label>
        
{field:campaign_desc}
        
<class="hint">{instructions:campaign_desc}</p>
    
        <
class="error">{error:campaign_short_desc}</p>    
        <
label>Short description:</label>
        
{field:campaign_short_desc}
        
<class="hint">{instructions:campaign_short_desc}</p>
        
        
{category_menu}
        
<label for="categories">Categories</label>
        <
select name="category[]" id="categories">
            
{select_options}
        
</select>
        
{/category_menu}
    
.........(I removed a load of fields here)........

    <
div class="clear"></div>
{/exp:safecracker} 
Profile
 
 
Posted: 14 January 2011 12:07 AM   [ Ignore ]   [ # 7 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

[removed]

$(document).ready(function(){
    
if ('{segment_3}' == ''{
       
$('input[name=campaign_status]:first').attr('checked''checked');
    
}
}
); 
Profile
 
 
Posted: 14 January 2011 12:10 AM   [ Ignore ]   [ # 8 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

Here’s my attempt at the relationship thing.

{exp:query sql="SELECT COUNT(*) AS rel_count FROM exp_relationships WHERE rel_child_id = '{segment_3}'"}
    {if 
'{rel_count}' != '0'}
        {field
:campaign_status}
    {
/if}
{
/exp:query} 
Profile
 
 
Posted: 14 January 2011 12:32 AM   [ Ignore ]   [ # 9 ]
Is a Really Great Dancer
RankRank
Total Posts:  61
Joined  2010-12-03

And an excellent attempt it is sir, thank you, both of those snippets do exactly what they should.

Profile
 
 
Posted: 14 January 2011 12:33 AM   [ Ignore ]   [ # 10 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

Sweet smile

Profile