Skip to content

Commit

Permalink
fixed select and checkbox state handlers, also adjusted the example f…
Browse files Browse the repository at this point in the history
…iles
  • Loading branch information
farinspace committed Sep 9, 2011
1 parent 4a5ebd9 commit 92b87ee
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 7 deletions.
34 changes: 34 additions & 0 deletions wp-content/themes/mytheme/metaboxes/checkbox-meta.php
Expand Up @@ -68,6 +68,40 @@
<?php $mb->the_field('cb_ex4_cb'); ?>
<input type="checkbox" name="<?php $mb->the_name(); ?>" value="xyz"<?php $mb->the_checkbox_state('xyz'); ?>/> xyz<br/>

<br/>
<br/>

<?php $items = array('a', 'b', 'c'); ?>

<?php foreach ($items as $i => $item): ?>

<!-- because I am not using a while loop with "have_fields()", I must
define the field name with "the_field()", the addition of the field hint
"WPALCHEMY_FIELD_HINT_CHECKBOX_MULTI" is used, in this case, to add
array brackets "[]" to the field name (cb_ex2[]) -->
<?php $mb->the_field('cb_ex5', WPALCHEMY_FIELD_HINT_CHECKBOX_MULTI); ?>

<input type="checkbox" name="<?php $mb->the_name(); ?>" value="<?php echo $item; ?>"<?php $mb->the_checkbox_state($item); ?>/> <?php echo $item; ?><br/>

<?php endforeach; ?>

<br/>
<br/>

<?php $items = array('a', 'b', 'c'); ?>

<?php foreach ($items as $i => $item): ?>

<!-- because I am not using a while loop with "have_fields()", I must
define the field name with "the_field()", the addition of the field hint
"WPALCHEMY_FIELD_HINT_CHECKBOX_MULTI" is used, in this case, to add
array brackets "[]" to the field name (cb_ex2[]) -->
<?php $mb->the_field('cb_ex6', WPALCHEMY_FIELD_HINT_CHECKBOX_MULTI); ?>

<input type="checkbox" name="<?php $mb->the_name(); ?>" value="<?php echo $item; ?>"<?php $mb->the_checkbox_state($item); ?>/> <?php echo $item; ?><br/>

<?php endforeach; ?>

<?php $mb->the_group_close(); ?>
<?php endwhile; ?>

Expand Down
12 changes: 11 additions & 1 deletion wp-content/themes/mytheme/metaboxes/select-meta.php
Expand Up @@ -24,7 +24,7 @@

<label>Select Single 3 (select multiple)</label><br/>

<?php $mb->the_field('s_single3', WPALCHEMY_FIELD_HINT_SELECT_MULTIPLE); ?>
<?php $mb->the_field('s_single3', WPALCHEMY_FIELD_HINT_SELECT_MULTI); ?>
<select name="<?php $mb->the_name(); ?>" multiple="multiple" size="5" style="height:75px;">
<option value="e"<?php $mb->the_select_state('e'); ?>>e</option>
<option value="f"<?php $mb->the_select_state('f'); ?>>f</option>
Expand All @@ -50,9 +50,19 @@
<option value="s"<?php $mb->the_select_state('s'); ?>>s</option>
</select>

<?php $mb->the_field('s_field2'); ?>
<select name="<?php $mb->the_name(); ?>">
<option value="">Select...</option>
<option value="q"<?php $mb->the_select_state('q'); ?>>q</option>
<option value="r"<?php $mb->the_select_state('r'); ?>>r</option>
<option value="s"<?php $mb->the_select_state('s'); ?>>s</option>
</select>

<?php $mb->the_group_close(); ?>
<?php endwhile; ?>

<p><a href="#" class="docopy-s_group button">Add</a></p>

<input type="submit" class="button-primary" name="save" value="Save">

</div>
12 changes: 6 additions & 6 deletions wp-content/wpalchemy/MetaBox.php
Expand Up @@ -5,7 +5,7 @@
* @copyright Copyright (c) 2009, Dimas Begunoff, http://farinspace.com
* @license http://en.wikipedia.org/wiki/MIT_License The MIT License
* @package WPAlchemy
* @version 1.4.14
* @version 1.4.15
* @link http://github.com/farinspace/wpalchemy
* @link http://farinspace.com
*/
Expand Down Expand Up @@ -1713,9 +1713,9 @@ function get_the_name($n = NULL)
{
$n = is_null($n) ? $this->subname : $n ;

if (!is_null($n)) return $this->id . '[' . $this->name . '][' . $this->current . '][' . $n . ']' ;
if (!is_null($n)) $the_field = $this->id . '[' . $this->name . '][' . $this->current . '][' . $n . ']' ;

$the_field = $this->id . '[' . $this->name . '][' . $this->current . ']' ;
else $the_field = $this->id . '[' . $this->name . '][' . $this->current . ']' ;
}
else
{
Expand All @@ -1730,7 +1730,7 @@ function get_the_name($n = NULL)
WPALCHEMY_FIELD_HINT_SELECT_MULTI,
WPALCHEMY_FIELD_HINT_SELECT_MULTIPLE,
);

if (in_array($this->hint, $hints))
{
$the_field .= '[]';
Expand Down Expand Up @@ -1822,13 +1822,13 @@ function is_selected($n, $v = NULL)
{
if (is_null($v))
{
$the_value = $this->get_the_value(NULL, TRUE);
$the_value = $this->get_the_value(NULL);

$v = $n;
}
else
{
$the_value = $this->get_the_value($n, TRUE);
$the_value = $this->get_the_value($n);
}

if (is_array($the_value))
Expand Down

0 comments on commit 92b87ee

Please sign in to comment.