function onDisplayField(&$field, &$item) { if (!in_array($field->field_type, self::$field_types)) { return; } $field->label = JText::_($field->label); $use_ingroup = $field->parameters->get('use_ingroup', 0); if ($use_ingroup) { $field->formhidden = 3; } if ($use_ingroup && empty($field->ingroup)) { return; } // initialize framework objects and other variables $document = JFactory::getDocument(); // **************** // Number of values // **************** $multiple = $use_ingroup || (int) $field->parameters->get('allow_multiple', 0); $max_values = $use_ingroup ? 0 : (int) $field->parameters->get('max_values', 0); $required = $field->parameters->get('required', 0); $required = $required ? ' required' : ''; $add_position = (int) $field->parameters->get('add_position', 3); // ************** // Value handling // ************** // Default value $value_usage = $field->parameters->get('default_value_use', 0); $default_value = $item->version == 0 || $value_usage > 0 ? $field->parameters->get('default_value', '') : ''; $default_value = $default_value ? JText::_($default_value) : ''; // Input field display size & max characters $display_label_form = (int) $field->parameters->get('display_label_form', 1); $size = (int) $field->parameters->get('size', 30); $maxlength = (int) $field->parameters->get('maxlength', 0); // client/server side enforced $placeholder = $display_label_form == -1 ? $field->label : JText::_($field->parameters->get('placeholder', '')); // create extra HTML TAG parameters for the form field $attribs = $field->parameters->get('extra_attributes', ''); if ($maxlength) { $attribs .= ' maxlength="' . $maxlength . '" '; } $attribs .= ' size="' . $size . '" '; // Custom HTML placed before / after form fields $pretext = $field->parameters->get('pretext_form', ''); $posttext = $field->parameters->get('posttext_form', ''); // ********************** // Create validation mask // ********************** $inputmask = $field->parameters->get('inputmask', false); $custommask = $field->parameters->get('custommask', false); $regexmask = $field->parameters->get('regexmask', false); static $inputmask_added = false; if ($inputmask && !$inputmask_added) { $inputmask_added = true; flexicontent_html::loadFramework('inputmask'); } // Initialise property with default value if (!$field->value) { $field->value = array($default_value); } // CSS classes of value container $value_classes = 'fcfieldval_container valuebox fcfieldval_container_' . $field->id; // Field name and HTML TAG id $fieldname = 'custom[' . $field->name . ']'; $elementid = 'custom_' . $field->name; $js = ""; $css = ""; if ($multiple) { // Add the drag and drop sorting feature if (!$use_ingroup) { $js .= "\n\t\t\tjQuery(document).ready(function(){\n\t\t\t\tjQuery('#sortables_" . $field->id . "').sortable({\n\t\t\t\t\thandle: '.fcfield-drag-handle',\n\t\t\t\t\tcontainment: 'parent',\n\t\t\t\t\ttolerance: 'pointer'\n\t\t\t\t});\n\t\t\t});\n\t\t\t"; } if ($max_values) { JText::script("FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED", true); } $js .= "\n\t\t\tvar uniqueRowNum" . $field->id . "\t= " . count($field->value) . "; // Unique row number incremented only\n\t\t\tvar rowCount" . $field->id . "\t= " . count($field->value) . "; // Counts existing rows to be able to limit a max number of values\n\t\t\tvar maxValues" . $field->id . " = " . $max_values . ";\n\t\t\t\n\t\t\tfunction addField" . $field->id . "(el, groupval_box, fieldval_box, params)\n\t\t\t{\n\t\t\t\tvar insert_before = (typeof params!== 'undefined' && typeof params.insert_before !== 'undefined') ? params.insert_before : 0;\n\t\t\t\tvar remove_previous = (typeof params!== 'undefined' && typeof params.remove_previous !== 'undefined') ? params.remove_previous : 0;\n\t\t\t\tvar scroll_visible = (typeof params!== 'undefined' && typeof params.scroll_visible !== 'undefined') ? params.scroll_visible : 1;\n\t\t\t\tvar animate_visible = (typeof params!== 'undefined' && typeof params.animate_visible !== 'undefined') ? params.animate_visible : 1;\n\t\t\t\t\n\t\t\t\tif((rowCount" . $field->id . " >= maxValues" . $field->id . ") && (maxValues" . $field->id . " != 0)) {\n\t\t\t\t\talert(Joomla.JText._('FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED') + maxValues" . $field->id . ");\n\t\t\t\t\treturn 'cancel';\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t// Find last container of fields and clone it to create a new container of fields\n\t\t\t\tvar lastField = fieldval_box ? fieldval_box : jQuery(el).prev().children().last();\n\t\t\t\tvar newField = lastField.clone();\n\t\t\t\t"; // NOTE: HTML tag id of this form element needs to match the -for- attribute of label HTML tag of this FLEXIcontent field, so that label will be marked invalid when needed // Update the new text field $js .= "\n\t\t\t\tvar theInput = newField.find('input.fcfield_textval').first();\n\t\t\t\ttheInput.val('');\n\t\t\t\ttheInput.attr('name', '" . $fieldname . "['+uniqueRowNum" . $field->id . "+']');\n\t\t\t\ttheInput.attr('id', '" . $elementid . "_'+uniqueRowNum" . $field->id . ");\n\t\t\t\t\n\t\t\t\t// Update inputmask\n\t\t\t\tvar has_inputmask = newField.find('input.has_inputmask').length != 0;\n\t\t\t\tif (has_inputmask) newField.find('input.has_inputmask').inputmask();\n\t\t\t\t\n\t\t\t\t// Re-init any select2 elements\n\t\t\t\tvar has_select2 = newField.find('div.select2-container').length != 0;\n\t\t\t\tif (has_select2) {\n\t\t\t\t\tnewField.find('div.select2-container').remove();\n\t\t\t\t\tnewField.find('select.use_select2_lib').select2('destroy').show().select2();\n\t\t\t\t}\n\t\t\t\t"; // Update select for textselect if it exists if ($field->field_type == 'textselect') { $js .= "\n\t\t\t\tnewField.parent().find('select.fcfield_textselval').val('');\n\t\t\t\t"; } // Add new field to DOM $js .= "\n\t\t\t\tlastField ?\n\t\t\t\t\t(insert_before ? newField.insertBefore( lastField ) : newField.insertAfter( lastField ) ) :\n\t\t\t\t\tnewField.appendTo( jQuery('#sortables_" . $field->id . "') ) ;\n\t\t\t\tif (remove_previous) lastField.remove();\n\t\t\t\t"; // Add new element to sortable objects (if field not in group) if (!$use_ingroup) { $js .= "\n\t\t\t\t//jQuery('#sortables_" . $field->id . "').sortable('refresh'); // Refresh was done appendTo ?\n\t\t\t\t"; } // Show new field, increment counters $js .= "\n\t\t\t\t//newField.fadeOut({ duration: 400, easing: 'swing' }).fadeIn({ duration: 200, easing: 'swing' });\n\t\t\t\tif (scroll_visible) fc_scrollIntoView(newField, 1);\n\t\t\t\tif (animate_visible) newField.css({opacity: 0.1}).animate({ opacity: 1 }, 800);\n\t\t\t\t\n\t\t\t\t// Enable tooltips on new element\n\t\t\t\tnewField.find('.hasTooltip').tooltip({'html': true,'container': newField});\n\t\t\t\t\n\t\t\t\trowCount" . $field->id . "++; // incremented / decremented\n\t\t\t\tuniqueRowNum" . $field->id . "++; // incremented only\n\t\t\t}\n\n\t\t\tfunction deleteField" . $field->id . "(el, groupval_box, fieldval_box)\n\t\t\t{\n\t\t\t\t// Find field value container\n\t\t\t\tvar row = fieldval_box ? fieldval_box : jQuery(el).closest('li');\n\t\t\t\t\n\t\t\t\t// Add empty container if last element, instantly removing the given field value container\n\t\t\t\tif(rowCount" . $field->id . " == 1)\n\t\t\t\t\taddField" . $field->id . "(null, groupval_box, row, {remove_previous: 1, scroll_visible: 0, animate_visible: 0});\n\t\t\t\t\n\t\t\t\t// Remove if not last one, if it is last one, we issued a replace (copy,empty new,delete old) above\n\t\t\t\tif(rowCount" . $field->id . " > 1) {\n\t\t\t\t\t// Destroy the remove/add/etc buttons, so that they are not reclicked, while we do the hide effect (before DOM removal of field value)\n\t\t\t\t\trow.find('.fcfield-delvalue').remove();\n\t\t\t\t\trow.find('.fcfield-insertvalue').remove();\n\t\t\t\t\trow.find('.fcfield-drag-handle').remove();\n\t\t\t\t\t// Do hide effect then remove from DOM\n\t\t\t\t\trow.slideUp(400, function(){ jQuery(this).remove(); });\n\t\t\t\t\trowCount" . $field->id . "--;\n\t\t\t\t}\n\t\t\t}\n\t\t\t"; $css .= ''; $remove_button = '<span class="fcfield-delvalue' . (JComponentHelper::getParams('com_flexicontent')->get('form_font_icons', 1) ? ' fcfont-icon' : '') . '" title="' . JText::_('FLEXI_REMOVE_VALUE') . '" onclick="deleteField' . $field->id . '(this);"></span>'; $move2 = '<span class="fcfield-drag-handle' . (JComponentHelper::getParams('com_flexicontent')->get('form_font_icons', 1) ? ' fcfont-icon' : '') . '" title="' . JText::_('FLEXI_CLICK_TO_DRAG') . '"></span>'; $add_here = ''; $add_here .= $add_position == 2 || $add_position == 3 ? '<span class="fcfield-insertvalue fc_before' . (JComponentHelper::getParams('com_flexicontent')->get('form_font_icons', 1) ? ' fcfont-icon' : '') . '" onclick="addField' . $field->id . '(null, jQuery(this).closest(\'ul\'), jQuery(this).closest(\'li\'), {insert_before: 1});" title="' . JText::_('FLEXI_ADD_BEFORE') . '"></span> ' : ''; $add_here .= $add_position == 1 || $add_position == 3 ? '<span class="fcfield-insertvalue fc_after' . (JComponentHelper::getParams('com_flexicontent')->get('form_font_icons', 1) ? ' fcfont-icon' : '') . '" onclick="addField' . $field->id . '(null, jQuery(this).closest(\'ul\'), jQuery(this).closest(\'li\'), {insert_before: 0});" title="' . JText::_('FLEXI_ADD_AFTER') . '"></span> ' : ''; } else { $remove_button = ''; $move2 = ''; $add_here = ''; $js .= ''; $css .= ''; } // Drop-Down select for textselect field type if ($field->field_type == 'textselect') { static $select2_added = false; if (!$select2_added) { $select2_added = true; flexicontent_html::loadFramework('select2'); } $sel_classes = ' fcfield_textselval use_select2_lib '; $sel_onchange = " jQuery(this).parent().find('input.fcfield_textval').val(jQuery(this).val()); jQuery(this).val('').select2('destroy').show().select2(); "; $sel_attribs = ' class="' . $sel_classes . '" onchange="' . $sel_onchange . '"'; $sel_fieldname = 'custom[' . $field->name . '_sel][]'; $sel_options = plgFlexicontent_fieldsText::buildSelectOptions($field, $item); $select_field = JHTML::_('select.genericlist', $sel_options, $sel_fieldname, $sel_attribs, 'value', 'text', array()); } else { $select_field = ''; } if ($js) { $document->addScriptDeclaration($js); } if ($css) { $document->addStyleDeclaration($css); } $classes = 'fcfield_textval' . $required; // Create attributes for JS inputmask validation $validate_mask = ''; switch ($inputmask) { case '__regex__': if ($regexmask) { $validate_mask = " data-inputmask-regex=\"" . $regexmask . "\" "; $classes .= ' inputmask-regex'; } break; case '__custom__': if ($custommask) { $validate_mask = " data-inputmask=\"" . $custommask . "\" "; $classes .= ' has_inputmask'; } break; default: if ($inputmask) { $validate_mask = " data-inputmask=\" 'alias': '" . $inputmask . "' \" "; $classes .= ' has_inputmask'; } } // Add placeholder tag parameter if not using validation mask, (if using vaildation mask then placeholder should be added a validation mask property) $attribs .= $placeholder ? ' placeholder="' . $placeholder . '" ' : ''; // ***************************************** // Create field's HTML display for item form // ***************************************** $field->html = array(); $n = 0; //if ($use_ingroup) {print_r($field->value);} foreach ($field->value as $value) { if (!strlen($value) && !$use_ingroup && $n) { continue; } // If at least one added, skip empty if not in field group $fieldname_n = $fieldname . '[' . $n . ']'; $elementid_n = $elementid . '_' . $n; // NOTE: HTML tag id of this form element needs to match the -for- attribute of label HTML tag of this FLEXIcontent field, so that label will be marked invalid when needed $text_field = $pretext . '<input value="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '" ' . $validate_mask . ' id="' . $elementid_n . '" name="' . $fieldname_n . '" class="' . $classes . '" type="text" ' . $attribs . ' />' . $posttext; $field->html[] = ' ' . $text_field . ' ' . $select_field . ' ' . ($use_ingroup ? '' : $move2) . ' ' . ($use_ingroup ? '' : $remove_button) . ' ' . ($use_ingroup || !$add_position ? '' : $add_here) . ' '; $n++; if (!$multiple) { break; } // multiple values disabled, break out of the loop, not adding further values even if the exist } if ($use_ingroup) { // do not convert the array to string if field is in a group } else { if ($multiple) { // handle multiple records $field->html = !count($field->html) ? '' : '<li class="' . $value_classes . '">' . implode('</li><li class="' . $value_classes . '">', $field->html) . '</li>'; $field->html = '<ul class="fcfield-sortables" id="sortables_' . $field->id . '">' . $field->html . '</ul>'; if (!$add_position) { $field->html .= '<span class="fcfield-addvalue ' . (JComponentHelper::getParams('com_flexicontent')->get('form_font_icons', 1) ? ' fcfont-icon' : '') . '" onclick="addField' . $field->id . '(this);" title="' . JText::_('FLEXI_ADD_TO_BOTTOM') . '">' . JText::_('FLEXI_ADD_VALUE') . '</span>'; } } else { // handle single values $field->html = '<div class="fcfieldval_container valuebox fcfieldval_container_' . $field->id . '">' . $field->html[0] . '</div>'; } } }
function onDisplayField(&$field, &$item) { // execute the code only if the field type match the plugin type if (!in_array($field->field_type, self::$field_types)) { return; } $field->label = JText::_($field->label); // initialize framework objects and other variables $document = JFactory::getDocument(); // some parameter shortcuts $default_value_use = $field->parameters->get('default_value_use', 0); $default_value = $item->version == 0 || $default_value_use > 0 ? $field->parameters->get('default_value', '') : ''; $maxlength = (int) $field->parameters->get('maxlength', 0); $size = (int) $field->parameters->get('size', 30); $multiple = $field->parameters->get('allow_multiple', 1); $max_values = (int) $field->parameters->get('max_values', 0); $required = $field->parameters->get('required', 0); $required = $required ? ' required' : ''; // add setMask function on the document.ready event $inputmask = $field->parameters->get('inputmask', false); $custommask = $field->parameters->get('custommask', false); static $inputmask_added = false; if ($inputmask && !$inputmask_added) { $inputmask_added = true; flexicontent_html::loadFramework('inputmask'); } // create extra HTML TAG parameters for the text form field $attribs = $field->parameters->get('extra_attributes', ''); if ($maxlength) { $attribs .= ' maxlength="' . $maxlength . '" '; } // Initialise property with default value if (!$field->value) { $field->value = array(); $field->value[0] = JText::_($default_value); } else { for ($n = 0; $n < count($field->value); $n++) { $field->value[$n] = htmlspecialchars($field->value[$n], ENT_QUOTES, 'UTF-8'); } } // Field name and HTML TAG id $fieldname = FLEXI_J16GE ? 'custom[' . $field->name . '][]' : $field->name . '[]'; $elementid = FLEXI_J16GE ? 'custom_' . $field->name : $field->name; $js = ""; if ($multiple) { if (!FLEXI_J16GE) { $document->addScript(JURI::root(true) . '/components/com_flexicontent/assets/js/sortables.js'); } // Add the drag and drop sorting feature $js .= "\r\n\t\t\tjQuery(document).ready(function(){\r\n\t\t\t\tjQuery('#sortables_" . $field->id . "').sortable({\r\n\t\t\t\t\thandle: '.fcfield-drag',\r\n\t\t\t\t\tcontainment: 'parent',\r\n\t\t\t\t\ttolerance: 'pointer'\r\n\t\t\t\t});\r\n\t\t\t});\r\n\t\t\t"; if ($max_values) { FLEXI_J16GE ? JText::script("FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED", true) : fcjsJText::script("FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED", true); } $js .= "\r\n\t\t\tvar uniqueRowNum" . $field->id . "\t= " . count($field->value) . "; // Unique row number incremented only\r\n\t\t\tvar rowCount" . $field->id . "\t= " . count($field->value) . "; // Counts existing rows to be able to limit a max number of values\r\n\t\t\tvar maxValues" . $field->id . " = " . $max_values . ";\r\n\r\n\t\t\tfunction addField" . $field->id . "(el) {\r\n\t\t\t\tif((rowCount" . $field->id . " >= maxValues" . $field->id . ") && (maxValues" . $field->id . " != 0)) {\r\n\t\t\t\t\talert(Joomla.JText._('FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED') + maxValues" . $field->id . ");\r\n\t\t\t\t\treturn 'cancel';\r\n\t\t\t\t}\r\n\t\t\t\t\r\n\t\t\t\tvar thisField \t = jQuery(el).prev().children().last();\r\n\t\t\t\tvar thisNewField = thisField.clone();\r\n\t\t\t\t\r\n\t\t\t\tjQuery(thisNewField).find('input').first().val(''); /* First element is the value input field, second is e.g remove button */\r\n\r\n\t\t\t\tvar has_inputmask = jQuery(thisNewField).find('input.has_inputmask').length != 0;\r\n\t\t\t\tif (has_inputmask) jQuery(thisNewField).find('input.has_inputmask').inputmask();\r\n\t\t\t\t\r\n\t\t\t\tvar has_select2 = jQuery(thisNewField).find('div.select2-container').length != 0;\r\n\t\t\t\tif (has_select2) {\r\n\t\t\t\t\tjQuery(thisNewField).find('div.select2-container').remove();\r\n\t\t\t\t\tjQuery(thisNewField).find('select.use_select2_lib').select2();\r\n\t\t\t\t}\r\n\t\t\t\t\r\n\t\t\t\tjQuery(thisNewField).css('display', 'none');\r\n\t\t\t\tjQuery(thisNewField).insertAfter( jQuery(thisField) );\r\n\r\n\t\t\t\tvar input = jQuery(thisNewField).find('input').first();\r\n\t\t\t\tinput.attr('id', '" . $elementid . "_'+uniqueRowNum" . $field->id . ");\r\n\t\t\t\t"; if ($field->field_type == 'textselect') { $js .= "\r\n\t\t\t\tthisNewField.parent().find('select.fcfield_textselval').val('');\r\n\t\t\t\t"; } $js .= "\r\n\t\t\t\tjQuery('#sortables_" . $field->id . "').sortable({\r\n\t\t\t\t\thandle: '.fcfield-drag',\r\n\t\t\t\t\tcontainment: 'parent',\r\n\t\t\t\t\ttolerance: 'pointer'\r\n\t\t\t\t});\r\n\t\t\t\t\r\n\t\t\t\tjQuery(thisNewField).show('slideDown');\r\n\t\t\t\t\r\n\t\t\t\trowCount" . $field->id . "++; // incremented / decremented\r\n\t\t\t\tuniqueRowNum" . $field->id . "++; // incremented only\r\n\t\t\t}\r\n\r\n\t\t\tfunction deleteField" . $field->id . "(el)\r\n\t\t\t{\r\n\t\t\t\tif(rowCount" . $field->id . " <= 1) return;\r\n\t\t\t\tvar row = jQuery(el).closest('li');\r\n\t\t\t\tjQuery(row).hide('slideUp', function() { this.remove(); } );\r\n\t\t\t\trowCount" . $field->id . "--;\r\n\t\t\t}\r\n\t\t\t"; $css = ' #sortables_' . $field->id . ' { float:left; margin: 0px; padding: 0px; list-style: none; white-space: nowrap; } #sortables_' . $field->id . ' li { clear: both; display: block; list-style: none; height: auto; position: relative; } #sortables_' . $field->id . ' li.sortabledisabled { background : transparent url(components/com_flexicontent/assets/images/move3.png) no-repeat 0px 1px; } #sortables_' . $field->id . ' li input { cursor: text;} #add' . $field->name . ' { margin-top: 5px; clear: both; display:block; } #sortables_' . $field->id . ' li .admintable { text-align: left; } #sortables_' . $field->id . ' li:only-child span.fcfield-drag, #sortables_' . $field->id . ' li:only-child input.fcfield-button { display:none; } '; $remove_button = '<input class="fcfield-button" type="button" value="' . JText::_('FLEXI_REMOVE_VALUE') . '" onclick="deleteField' . $field->id . '(this);" />'; $move2 = '<span class="fcfield-drag">' . JHTML::image(JURI::base() . 'components/com_flexicontent/assets/images/move2.png', JText::_('FLEXI_CLICK_TO_DRAG')) . '</span>'; } else { $remove_button = ''; $move2 = ''; $js = ''; $css = ''; } // Drop-Down select for textselect field type if ($field->field_type == 'textselect') { static $select2_added = false; if (!$select2_added) { $select2_added = true; flexicontent_html::loadFramework('select2'); } $sel_classes = ' fcfield_textselval use_select2_lib '; $sel_onchange = "this.getParent().getElement('input.fcfield_textval').setProperty('value', this.getProperty('value')); this.setProperty('value', ''); "; $sel_attribs = ' class="' . $sel_classes . '" onchange="' . $sel_onchange . '"'; $fieldname_sel = FLEXI_J16GE ? 'custom[' . $field->name . '_sel][]' : $field->name . '_sel[]'; $sel_ops = plgFlexicontent_fieldsText::buildSelectOptions($field, $item); $select_field = JHTML::_('select.genericlist', $sel_ops, $fieldname_sel, $sel_attribs, 'value', 'text', array()); } else { $select_field = ''; } if ($js) { $document->addScriptDeclaration($js); } if ($css) { $document->addStyleDeclaration($css); } if ($custommask && $inputmask == "__custom__") { $validate_mask = " data-inputmask=\" " . $custommask . " \" "; } else { $validate_mask = $inputmask ? " data-inputmask=\" 'alias': '" . $inputmask . "' \" " : ""; } $classes = 'fcfield_textval inputbox' . $required . ($inputmask ? ' has_inputmask' : ''); $field->html = array(); $n = 0; foreach ($field->value as $value) { $elementid_n = $elementid . '_' . $n; $text_field = '<input ' . $validate_mask . ' id="' . $elementid_n . '" name="' . $fieldname . '" class="' . $classes . '" type="text" size="' . $size . '" value="' . $value . '" ' . $attribs . ' />'; $field->html[] = ' ' . $text_field . ' ' . $select_field . ' ' . $move2 . ' ' . $remove_button . ' '; $n++; if (!$multiple) { break; } // multiple values disabled, break out of the loop, not adding further values even if the exist } if ($multiple) { // handle multiple records $_list = "<li>" . implode("</li>\n<li>", $field->html) . "</li>\n"; $field->html = ' <ul class="fcfield-sortables" id="sortables_' . $field->id . '">' . $_list . '</ul> <input type="button" class="fcfield-addvalue" onclick="addField' . $field->id . '(this);" value="' . JText::_('FLEXI_ADD_VALUE') . '" /> '; } else { // handle single values $field->html = $field->html[0]; } }