diff --git a/classes/controllers/FrmFieldsController.php b/classes/controllers/FrmFieldsController.php index 5dc433ea23..b06f99287b 100644 --- a/classes/controllers/FrmFieldsController.php +++ b/classes/controllers/FrmFieldsController.php @@ -242,6 +242,12 @@ public static function load_single_field( $field_object, $values, $form_id = 0 ) if ( $ajax_loading && $ajax_this_field ) { $li_classes = self::get_classes_for_builder_field( array(), $display, $field_obj ); + + if ( isset( $values['placeholder_manifest'] ) ) { + self::add_builder_placeholder_to_manifest( $field_object, $display, $li_classes, $values['placeholder_manifest'] ); + return; + } + include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/ajax-field-placeholder.php'; return; } @@ -271,6 +277,32 @@ public static function load_single_field( $field_object, $values, $form_id = 0 ) require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php'; } + /** + * Record shared attributes and leave a minimal placeholder in its grid row. + * + * @since x.x + * + * @param object $field Field object with its id and owning form. + * @param array $display Field display options, including the builder type. + * @param string $li_classes Classes used by the original placeholder. + * @param object{definitions: array, fields: array}&\stdClass $manifest Shared attribute definitions and ordered field records. + * + * @return void + */ + private static function add_builder_placeholder_to_manifest( $field, array $display, $li_classes, $manifest ) { + $definition = array( $li_classes . ' frm_field_loading', (int) $field->form_id, $display['type'] ); + $index = array_search( $definition, $manifest->definitions, true ); + + if ( false === $index ) { + $index = count( $manifest->definitions ); + $manifest->definitions[] = $definition; + } + + $placeholder = count( $manifest->fields ); + $manifest->fields[] = array( (int) $field->id, $index ); + echo '
  • '; + } + /** * @since 3.0 * diff --git a/classes/views/frm-forms/form.php b/classes/views/frm-forms/form.php index cf84a6706f..94ee89b24e 100644 --- a/classes/views/frm-forms/form.php +++ b/classes/views/frm-forms/form.php @@ -52,6 +52,13 @@ $grid_helper = new FrmFieldGridHelper(); $values['count'] = 0; + if ( ! empty( $values['ajax_load'] ) ) { + $values['placeholder_manifest'] = (object) array( + 'definitions' => array(), + 'fields' => array(), + ); + } + foreach ( $values['fields'] as $field ) { ++$values['count']; $grid_helper->set_field( $field ); @@ -62,10 +69,22 @@ } $grid_helper->force_close_field_wrapper(); unset( $grid_helper ); - } + }//end if ?> + fields ) ) { + wp_print_inline_script_tag( + wp_json_encode( $values['placeholder_manifest'], JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT ), + array( + 'id' => 'frm-field-placeholders', + 'type' => 'application/json', + ) + ); + } + ?> +