Using P&T Dropdown with Safecracker
Posted: 04 October 2010 10:32 PM   [ Ignore ]
Wallflower
Rank
Total Posts:  11
Joined  2010-09-21

Hello,

I need to use optgroups with my dropdown menu so decided to use PT Dropdown. (part of Brandons Dive Bar)

I’ve created a SafeCracker form without using the {custom_fields} loop for the most flexibility of layout.
When I use PT Dropdown with the Dive Bar optgroup example I get a “Content Encoding Error” on my Safecracker form.

If you’ve managed to get PT Dropdown and Safecracker without custom fields loop working can you post an example please.

Thanks
John

[ Edited: 04 October 2010 10:36 PM by johnniefp ]
Profile
 
 
Posted: 04 October 2010 11:11 PM   [ Ignore ]   [ # 1 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

Can you show us your template code? Also, do you have GZIP turned on?

Profile
 
 
Posted: 05 October 2010 12:39 AM   [ Ignore ]   [ # 2 ]
Wallflower
Rank
Total Posts:  11
Joined  2010-09-21

I did have GZIP turned on, when I turned it off the page spat our loads of PHP errors.

A PHP Error was encountered
Severity
Notice
Message
Undefined offset0
Filename
libraries/Template.php
Line Number
4089 

My offending PT Dropdown now contains ‘Array’ (It’s fine if I go to add an entry the traditional backend way)

My template code is as follows

<select name="q7"}
  {options
:q7} 
    
<option value="{option_value}" {selected}>{option_name}</option>
  
{/options:q7}
</select

I perhaps naively thought that Safecracker would recognise the fieldtype and do something automagically.

Since posting here and while trying to solve this I came across this post.
Dive Bar fields in SAEF?

I’m only using PT Dropdown as I require optgroups - if there is no way to implement PT Dropdown can you think of a way of making optgroups with Safecracker?

Thanks
John

Profile
 
 
Posted: 05 October 2010 12:42 AM   [ Ignore ]   [ # 3 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

It’d probably require some additional tags to get optgroups working right. It’s something I’ll have to think about.

In the mean time, have you tried using the field tag?

{field:q7} 
Profile
 
 
Posted: 05 October 2010 03:28 AM   [ Ignore ]   [ # 4 ]
Wallflower
Rank
Total Posts:  11
Joined  2010-09-21

The field tag seems to work great.
I went through the docs and missed that one, thanks for the pointer.

It’s getting late here now so will pick up and test this tomorrow but a brief look shows nothing but happiness.

This module is truly turning out to be a life saver on a 36 custom field form.

Profile
 
 
Posted: 13 February 2011 09:40 PM   [ Ignore ]   [ # 5 ]
Wallflower
Rank
Total Posts:  17
Joined  2011-02-04

Hey, Rob,

That works to display the field, but I have a bit of a complication.  I’m using a jquery script that displays the instructions for each field in a fancy tooltip.  The script gets the text for the tooltip from the “title=” from each field (and I’m using title=”{instructions:custom_field_name}”).  If I can’t specify the title in each field, I can’t get the tooltip in there; and worse, if the title isn’t specified, the field jumps when you hover over it.  (That’s what happens when you’re a dunce at jquery and you use someone else’s code!) 

I realize this probably goes above and beyond, but do you have any suggestions for an override of the P&T field types so I could get the title= in each of them, rather than simply using {field:custom_field_name}?

Profile
 
 
Posted: 13 February 2011 10:19 PM   [ Ignore ]   [ # 6 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

If you’re using a field from the P&T Field Pack (Dropdown, Checkboxes, Multiselect, Radio Buttons) you can use an options loop:

<select name="field_name">
  
{options:field_name} 
    
<option value="{option_value}" {selected}>{option_name}</option>
  
{/options:field_name}
</select

Or

{options:field_name} 
    
<label><input type="checkbox" value="{option_value}" {checked} />{option_name}</label>
  
{/options:field_name} 

Or

{options:field_name} 
    
<label><input type="radio" value="{option_value}" {checked} />{option_name}</label>
  
{/options:field_name} 

You can also do this with the P&T Dive Bar fields (Pill, Switch, List) but that kind of defeats the purpose of those because they have their special UI elements.

The final alternative is to add your title dynamically, using JS.

...

script >
$(function()
{
    
$('#field_name').attr('title''{instructions:field_name}');
});
< /
script >
{/exp:safecracker} 
Profile
 
 
Posted: 14 February 2011 12:28 AM   [ Ignore ]   [ # 7 ]
Wallflower
Rank
Total Posts:  17
Joined  2011-02-04

Thanks.  Worked perfectly.  Bookmarked this page!

Profile
 
 
Posted: 14 February 2011 01:02 AM   [ Ignore ]   [ # 8 ]
Wallflower
Rank
Total Posts:  17
Joined  2011-02-04

Sorry.  Spoke too soon.  They LOOKED OK, but there’s something fishy with the radio buttons.  The other two worked OK.

If I use the radio button option, I can’t select one.  No selected state displays. With {field:custom_field_name} I can select.

Profile