Print OptionList with Key/Value pairs


(Nic Hubbard) #1

I am working on updating my Urban Airship Trigger Action to be more robust. In doing this, I want to print out an option list that shows key/value pairs, similar to what you see on a Custom Form Selection field:

 

Screen%20Shot%202013-10-02%20at%209.50.5

 

Looking at the code for the field, it looks like a lot of it is duplicated from the option_list.inc form field, but in looking at that file I don't see any options for having key/value pairs.

 

Is there an easy way to print this type of field, such as setting an edit param? Or am I going to have to write this all manually like is done in the Custom Form Select question?


(Bart Banda) #2

I guess it would probably be easiest to just write some custom jQuery for it, here is a fiddle I found after a quick google.

http://jsfiddle.net/qBURS/2/

 

Is that something that you are after?


(Nic Hubbard) #3

I guess it would probably be easiest to just write some custom jQuery for it, here is a fiddle I found after a quick google.

http://jsfiddle.net/qBURS/2/

 

Is that something that you are after?

 

No. Sorry, maybe I didn't explain well enough. I am talking about PHP within my trigger_action_urban_airship.inc file.  So, for the tokens field, I am using the standard Matrix option list, which nicely prints the up and down arrows:

$device_token = array_get_index($settings, 'airship_device_token', '');
if ($write_access) {
   echo '<p>';
   $option_list = new Asset_Attribute_Option_List(0, $device_token, ',');
   $option_list->setEditParam('width', 85);
   $option_list->paint('airship_device_token');
   echo '</p>';
   echo '<p>'.translate('trigger_action_urban_airship_device_token_instructions').'</p>';
} else {
   echo '<p>'.str_replace(',', '<br />', $device_token).'</p>';
}

But this only a provides a single field, not key/value pair fields as I have shown and mentioned in the original post. Matrix uses this for the Custom Form Select field screen, but looking at the code the the implementation of it is quite large and an overkill for what I need.

 

So I was wondering if the there is an easier way to implement this kind of a field in Matrix. Such as some special edit params to create the Asset_Attribute_Option_List object.


(Bart Banda) #4

Ah I see. Probably a good one for the Squiz Labs guys to answer...


(Nic Hubbard) #5

Anyone? Ashish?


(Benjamin Pearson) #6

Sorry Nic, we are in the middle of moving offices, so we have been pretty quiet here. But to answer your question, no option list does not have any setting to print both keys and values. Unfortunately, you will have to do it manually like form select.


(Nic Hubbard) #7

Sorry Nic, we are in the middle of moving offices, so we have been pretty quiet here. But to answer your question, no option list does not have any setting to print both keys and values. Unfortunately, you will have to do it manually like form select.

 

Bummer. Thanks for letting me know.