]> git.nbdom.net Git - nb.git/commitdiff
lib/php/db/field.php
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Sun, 18 Feb 2018 22:13:12 +0000 (22:13 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Sun, 18 Feb 2018 22:13:12 +0000 (22:13 +0000)
lib/php/db/field.php

index 7ea29a5a9adb9e8c2c1f0ec911dd2183c4be4270..9e8bbfc313fbf8b9c74237bbdea44d95d5058061 100644 (file)
@@ -117,11 +117,11 @@ class field extends nb {
 
     $html = '';
 
-               $values = (array)$values;
-               $suff = count( $values ) > 1 ? '[]' : '';
+               $multi = is_array($values) ? true : false;
+               $suff = $multi ? '[]' : '';
                if ($type === null) $type = $this->html_type();
 
-               foreach ($values as $value) {
+               foreach ((array)$values as $value) {
        $html .= '<div class="label '.$this->name.'">'
                                .'<label for="'.$this->name.'">'.htmlspecialchars(prettyText($this->name)).'</label>'
                        ;
@@ -142,7 +142,7 @@ class field extends nb {
                                }
 
        $html .= '<'.$tag
-               .' name="'.$this->preffix.$this->name.$suff.'"'
+               .' name="'.$this->preffix.$this->name . ($multi ? '[]' : '') . '"'
                .( ($size and $tag != 'textarea') ? ' size="'.$size.'"' : '')
                .($tag == 'textarea' ? '>'.$value.'</textarea>' : ' type="'.$type.'" value="'.htmlspecialchars($value).'" />')
        ;
@@ -150,7 +150,7 @@ class field extends nb {
        }
 
                        # If more than one value, add js code to add more values
-                       if ($suff) $html .= '<a href="#" onclick="var i=this.parentNode;var j=i.cloneNode(true);j.querySelectorAll(\'input, textarea, select\').forEach(function(e) {e.value=\'\';}); i.parentNode.insertBefore(j, i.nextSibling);console.log(i.className); return false;">+</a>';
+                       if ($multi) $html .= '<a href="#" onclick="var i=this.parentNode;var j=i.cloneNode(true);j.querySelectorAll(\'input, textarea, select\').forEach(function(e) {e.value=\'\';}); i.parentNode.insertBefore(j, i.nextSibling);console.log(i.className); return false;">+</a>';
 
        $html .= '</div>'.NB_EOL;
                }