diff --git a/views/_admin/pages/create.html.php b/views/_admin/pages/create.html.php index aa8d3fe..2ddc974 100644 --- a/views/_admin/pages/create.html.php +++ b/views/_admin/pages/create.html.php @@ -1,3 +1,6 @@ +

Create

@@ -15,10 +18,28 @@ $v) { if(!isset($v['form']['position']) || $v['form']['position'] != 'options') { - ?> - form->field($k, $v['form']);?> - form->field($k, $v['form']); + } else { + // For tags... it's an array of values, so it breaks the form->field() helper method + if(isset($v['form']['class']) && $v['form']['class'] == 'tagger') { + // So capture its value and we'll use it to add the tags with the jQuery plugin + if(is_object($document) && isset($document->$k)) { + $v['value'] = $document->$k->data(); + } else { + $v['value'] = array(); + } + $v['form']['id'] = ucfirst($k); + $tagger_javascript .= '$("#' . ucfirst($k) . '").addTag("' . implode(',', $v['value']) . '");'; + unset($document->$k); + echo $this->form->field($k, $v['form']); + if(isset($v['form']['help_text'])) { + echo '
' . $v['form']['help_text'] . '
'; + } + } + } + } } ?> form->submit('Add ' . $display_name); ?> html->link('Cancel', array('admin' => $this->minervaHtml->admin_prefix, 'library' => 'minerva', 'controller' => 'pages', 'action' => 'index', 'args' => array($document_type))); ?> @@ -35,10 +56,31 @@ foreach($fields as $k => $v) { if(isset($v['form'])) { if(isset($v['form']['position']) && $v['form']['position'] == 'options') { - echo $this->form->field($k, $v['form']); - if(isset($v['form']['help_text'])) { - echo '
' . $v['form']['help_text'] . '
'; + // if(!isset($v['type']) || $v['type'] != 'array') { + if(!isset($v['form']['class']) || $v['form']['class'] != 'tagger') { + echo $this->form->field($k, $v['form']); + if(isset($v['form']['help_text'])) { + echo '
' . $v['form']['help_text'] . '
'; + } + } else { + // For tags... it's an array of values, so it breaks the form->field() helper method + if(isset($v['form']['class']) && $v['form']['class'] == 'tagger') { + // So capture its value and we'll use it to add the tags with the jQuery plugin + if(is_object($document) && isset($document->$k)) { + $v['value'] = $document->$k->data(); + } else { + $v['value'] = array(); + } + $v['form']['id'] = ucfirst($k); + $tagger_javascript .= '$("#' . ucfirst($k) . '").addTag("' . implode(',', $v['value']) . '");'; + unset($document->$k); + echo $this->form->field($k, $v['form']); + if(isset($v['form']['help_text'])) { + echo '
' . $v['form']['help_text'] . '
'; + } + } } + } } } @@ -56,4 +98,9 @@ form->end(); ?> -
\ No newline at end of file +
+ \ No newline at end of file diff --git a/views/_admin/pages/update.html.php b/views/_admin/pages/update.html.php index 84b2b67..1afeb16 100644 --- a/views/_admin/pages/update.html.php +++ b/views/_admin/pages/update.html.php @@ -1,3 +1,6 @@ +

Update

@@ -11,9 +14,28 @@ $v) { if(!isset($v['form']['position']) || $v['form']['position'] != 'options') { - ?> - form->field($k, $v['form']);?> - form->field($k, $v['form']); + } else { + // For tags... it's an array of values, so it breaks the form->field() helper method + if(isset($v['form']['class']) && $v['form']['class'] == 'tagger') { + // So capture its value and we'll use it to add the tags with the jQuery plugin + if(is_object($document) && isset($document->$k)) { + $v['value'] = $document->$k->data(); + } else { + $v['value'] = array(); + } + $v['form']['id'] = ucfirst($k); + $tagger_javascript .= '$("#' . ucfirst($k) . '").addTag("' . implode(',', $v['value']) . '");'; + unset($document->$k); + echo $this->form->field($k, $v['form']); + if(isset($v['form']['help_text'])) { + echo '
' . $v['form']['help_text'] . '
'; + } + } + } + } } ?> @@ -30,14 +52,31 @@ $v) { if(isset($v['form']['position']) && $v['form']['position'] == 'options') { - ?> - form->field($k, $v['form']);?> - - ' . $v['form']['help_text'] . ''; + // if(!isset($v['type']) || $v['type'] != 'array') { + if(!isset($v['form']['class']) || $v['form']['class'] != 'tagger') { + echo $this->form->field($k, $v['form']); + if(isset($v['form']['help_text'])) { + echo '
' . $v['form']['help_text'] . '
'; + } + } else { + // For tags... it's an array of values, so it breaks the form->field() helper method + if(isset($v['form']['class']) && $v['form']['class'] == 'tagger') { + // So capture its value and we'll use it to add the tags with the jQuery plugin + if(is_object($document) && isset($document->$k)) { + $v['value'] = $document->$k->data(); + } else { + $v['value'] = array(); + } + $v['form']['id'] = ucfirst($k); + $tagger_javascript .= '$("#' . ucfirst($k) . '").addTag("' . implode(',', $v['value']) . '");'; + unset($document->$k); + echo $this->form->field($k, $v['form']); + if(isset($v['form']['help_text'])) { + echo '
' . $v['form']['help_text'] . '
'; + } + } } - } + } } ?> @@ -46,4 +85,9 @@ form->end(); ?> -
\ No newline at end of file +
+ \ No newline at end of file diff --git a/webroot/js/jquery/jquery.tagger.js b/webroot/js/jquery/jquery.tagger.js index 57267c8..8bdbfc3 100644 --- a/webroot/js/jquery/jquery.tagger.js +++ b/webroot/js/jquery/jquery.tagger.js @@ -14,6 +14,14 @@ You should have received a copy of the GNU General Public License along with this program. If not, see + + This is a modified version of Tagger, for use with Minerva CMS. + The edits shouldn't change how Tagger works, but it enhances it with some + sanity checking and appends the inputs directly to the form element instead + of to the .data('list') where the tags are added visually (with removal option). + This was the only way the form data seemed to see the fields in my experience. + I'm not sure how it worked before. It could be the positioning of the form + within the layout or something weird. This makes it all work though. */ (function($){ @@ -33,15 +41,38 @@ }) .data('hidden',i); var l = $(this).data('list'); - $(l).append(t).append(i); + // Originally, it appended both label and input field + //$(l).append(t).append(i); + // + // Append the tag (and remove option) to the list of tags visually, but not the hidden input + $(l).append(t); + + // Must append the input to the form! It's not being seen otherwise. + var elem = $(this); + var form = elem.length > 0 ? $(elem[0].form) : $(); + $(form).append(i); } return this; }; - + })(jQuery); -jQuery(function(){ +jQuery(function(){ + // This ensures that the tagger text input field is disabled upon submit. + // Otherwise, we're saving empty values in a tag array in the database. + var input = $('.tagger'); + var form = input.length > 0 ? $(input[0].form) : $(); + $(form).bind('submit', function() { + $(input).attr('disabled', true); + }); + $('.tagger').each(function(i){ + // Make the input a multiple (array) input if it isn't already + var n = $(this).attr('name'); + if(n.substr(-2) != '[]') { + $(this).attr('name', n + '[]'); + } + $(this).data('name', $(this).attr('name')); var b = $('