Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

  1. Index
  2. » Archives
  3. » drop down lists for custom fields

#13 2006-03-22 16:41:09

M_i
Member
Registered: 2006-03-05
Posts: 122

Re: drop down lists for custom fields

duchamp wrote:

Well, well … I updated my previous post (before Kemie’s post) with the “right” code and it’s working!

That’s wonderful! Thanks duchamp!

Building on your work, I got this together for occasions where you just need on / off or yes / no (i.e. 1 or 0):

For radio switches:

<code>function radioCustField($num,$field,$content)
{
$name = (‘custom_’.$num);
return graf($field . br . yesnoRadio($name,$content)); }</code><br><br>

You can replace ‘yesnoRadio’ with ‘onoffRadio’ if you want your options to be on/off instead of yes/no;

For checkboxes (with the box in front of the custom field name):

<code>function checkCustField($num,$field,$content)
{
$name = (‘custom_’.$num);
return graf(checkbox($name,$content) . $field); }</code><br><br>

replace ‘checkbox’ with ‘checkbox2’ if you want it unchecked by default – see lib/txplib_forms.php

Of course the line of the custom field you want to use this for needs to read:

($custom_3_set) ? radioCustField( 3, $custom_3_set, $custom_3 ) : '',
or
($custom_3_set) ? checkCustField( 3, $custom_3_set, $custom_3 ) : '',
or whatever you named your new function.<br><br>

I don’t know if I’ve done this correctly (that is, according to the rules of the art), because honestly, I have no training in this besides trial & error. But it puts 1s and 0s in the right places in the database – and for now, that’s good enough for me.

- Iris

Offline

#14 2006-03-22 17:28:24

Inspired
Plugin Author
From: Kiev, Ukraine
Registered: 2005-01-28
Posts: 87
Website

Re: drop down lists for custom fields

I thought about the subject recently, particularly that a plugin might insert javascript to turn text inputs into editable selects


Plugin Composer — admin plugin to write your own plugins

Offline

#15 2006-03-22 18:23:22

duchamp
Member
From: Patagonia
Registered: 2005-02-03
Posts: 222
Website

Re: drop down lists for custom fields

Working on the radio buttons option …

1) In Admin Tab I named Tempo the Custom Field #4

2) In txp_article.php change the line refered to Custom field 4 (around line 372) to this:

<code>($custom_4_set) ? DecideField( 4, $custom_4_set, $custom_4 ) : ‘’, </code><br />

3) Create a New Function called DecideField (Near line 630):

<code> function DecideField($num,$field,$content) { $name = (‘custom_’.$num); $Decided = array( ‘slow’ => ‘slow’, ‘middle’ => ‘middle’, ‘high’ => ‘high’ ); $out[] = “<p>$field”; foreach($Decided as $a=>$b) { $out[] = tag(radio($name,$a,($content==$a)?1:0).$b,‘label’); } return join(br.n,$out); }</code><br />

It works! the selected option is inserted into the database … but need to be improbed ‘cause after save the post the Selected option it’s not checked
There’s something between this Function and the Default radio function that Im missing!

Last edited by duchamp (2006-03-22 19:02:05)

Offline

#16 2006-03-22 18:59:07

duchamp
Member
From: Patagonia
Registered: 2005-02-03
Posts: 222
Website

Re: drop down lists for custom fields

Updated

Now it’s fully working.
If you want the three options in a row change the last piece of the function to this:

<code> return join($out); }</code>

I think it could work.

Anyway, the markup it’s no right, I need to parse the <code><p> and </p> tags</code> to open and close the options … just a detail.

Last edited by duchamp (2006-03-22 19:01:50)

Offline

#17 2006-03-22 20:37:13

Inspired
Plugin Author
From: Kiev, Ukraine
Registered: 2005-01-28
Posts: 87
Website

Re: drop down lists for custom fields

Here’s a quick proof-of-concept test plugin to convert custom field inputs into editable selects, as i mentioned above – download ied_editable_select – check it out and tell me what you think. Enable it and have a look at custom_1

(well, anyway, it is in fact more simple to make radio buttons or checkboxes of it, just get inspired)


Plugin Composer — admin plugin to write your own plugins

Offline

#18 2006-03-22 21:18:12

duchamp
Member
From: Patagonia
Registered: 2005-02-03
Posts: 222
Website

Re: drop down lists for custom fields

Thanks! it works ok
Just a few details:

1) the Path to arrow images could be changed (maybe saving the three images into the images folder)

2) there’s something wrong with the DIV with Overflow ‘cause it has an horizontal scrollbar, but its just a question of pixeles …

Offline

#19 2006-03-22 23:20:59

Inspired
Plugin Author
From: Kiev, Ukraine
Registered: 2005-01-28
Posts: 87
Website

Re: drop down lists for custom fields

ok, Alex, download the plugin again – i’ve included the images into the plugin’s body.


Plugin Composer — admin plugin to write your own plugins

Offline

#20 2006-04-05 21:10:38

marios
Archived Plugin Author
Registered: 2005-03-12
Posts: 1,253

Re: drop down lists for custom fields

I liked the solution , allthough not as good as the real thing, but this could be good, if you just want to give some option quickly, with out much time,
The background hover for the options didn’t work well in Safari, so I made some small modifications on the CSS, to make it look more real.(I’ve no Idea though how it looks in windows)
You can replace the CSS with this one, the options drop down now extends to the full width of the dropdown box and is in em;
<code> .selectBoxArrow{ margin-top:1px; float:left; position:absolute; right:1px; } .selectBoxInput{ border:0px; padding-left:1px; height:18px;
width:12.5em; position:absolute; top:0px; left:0px; }

.selectBox{ border:1px solid #7f9db9; height:20px;
width:12.5em;

} .selectBoxOptionContainer{ position:absolute; border:1px solid #7f9db9; height:100px;
width:12.5em; background-color:#eee; left:-1px; top:18px; visibility:hidden; overflow:auto; } .selectBoxAnOption{ font-family:arial; font-size:10px; cursor:default; margin:1px; overflow:hidden; white-space:nowrap;
display:block;color:#333;
background-color: #eee; }

.selectBoxAnOption:hover {
background-color: #bbb !important;
color:#333;
display:block;}</code>


⌃ ⇧ < ⌃ ⇧ >

Offline

#21 2006-04-05 21:44:32

Inspired
Plugin Author
From: Kiev, Ukraine
Registered: 2005-01-28
Posts: 87
Website

Re: drop down lists for custom fields

Thanks marios, I’ve updated the plugin with your css, it worked well for me.
Indeed the plugin is a quick one, I have in mind ideas for making something closer to a real thing out of it, but got no time at the moment.


Plugin Composer — admin plugin to write your own plugins

Offline

#22 2006-04-05 23:37:55

marios
Archived Plugin Author
Registered: 2005-03-12
Posts: 1,253

Re: drop down lists for custom fields

time is a rare thing nowadays,btw.:The problem starts with text resizing,I might take a look again to fine tune the CSS a little more and have the height values in Ems as well, so it doesn’t scale out of proportion.

regards, marios


⌃ ⇧ < ⌃ ⇧ >

Offline

#23 2006-04-06 00:04:43

Inspired
Plugin Author
From: Kiev, Ukraine
Registered: 2005-01-28
Posts: 87
Website

Re: drop down lists for custom fields

OK, you can send me to email when you’re done with it.


Plugin Composer — admin plugin to write your own plugins

Offline

#24 2006-05-05 07:53:06

gerhard
Plugin Author
From: London, UK
Registered: 2005-06-29
Posts: 409
Website

Re: drop down lists for custom fields

Sorry guys, but I didn’t have time for the forum lately. I got an e-mail from Alex yesterday enquiring about this > custom_advanced.jpg . Since time is not on my side – again – I will just share the modded files (they are semi-commented). Will join the chat later on – promise : ).

textpattern/lib/txplib_forms.txt
textpattern/include/txp_article.txt

p.s.: an article on my blog is long overdue…

Offline

  1. Index
  2. » Archives
  3. » drop down lists for custom fields

Board footer

Powered by FluxBB