1

I want to build a views page where user searches for a text (without auto-complete) by entering query in a text box and clicking a button on drupalgap, and I want to have flag links on the results On the documentation page of drupalgap views exposed filters, http://docs.drupalgap.org/7/Views/Views_Exposed_Filters "building your own forms and constructing own URL parameters" is mentioned but there is no example of that. Is there any example/tutorial of usage like that? Thanks in advance,

Update: This is the function that I define my form:

function form_custom_form(form, form_state) {
      try {
        form.elements['name'] = {
          type: 'textfield',
          title: 'Kart No',
          required: true
        };
        form.elements['submit'] = {
          type: 'submit',
          value: 'Ara'
        };
        form.elements['my_markup'] = {
          markup: '<ul id="arac_getir2_view" data-role="listview" class="ui-listview ui-listview-inset ui-corner-all ui-shadow"></ul>'
        };
        return form;
      }
      catch (error) { console.log('my_module_custom_form - ' + error); }
    }

This is the code which works:

function form_custom_form_submit(form, form_state) {
  form_value = form_state.values['name'];
  form.elements['my_markup'] = {
    markup: '<ul id="arac_getir2_view" data-role="listview" class="ui-listview ui-listview-inset ui-corner-all ui-shadow"></ul>'
  };
  arac_getir2_pageshow();
}
/*catch (error) { console.log('form_custom_form_submit - ' + error); }*/

function arac_getir2_pageshow() {
  var path_to_view = 'arac_getir';
  views_datasource_get_view_result(path_to_view, {
    success: function (data) {
      if (data.nodes.length > 0) {
        var items = [];

        $.each(data.nodes, function(index, object){
          var node = object.node;
          items.push(
            l(node.title, '#') +  
            flag_quick_link(
                    'ara_getir', // The flag's machine name.
                    'node', // The entity type.
                    node.nid, // The entity id.
                    parseInt(node.flagged) ? true : false // The current flag status.
                    )
            );
        });
        console.log(items);
        drupalgap_item_list_populate('#arac_getir2_view', items);

      }
    }
  });
}

This is the one which does not:

  function form_custom_form_submit(form, form_state) {
    form_value = form_state.values['name'];
    arac_getir_page();
  }

  function arac_getir_page() {
    try {
      var content = {};
      content['arac_list'] = {
        theme: 'view',
        format: 'ul',
        format_attributes: {
          /*'data-inset': 'true',*/
          'data-split-icon': 'star' /*the icon to use for the flag button */
        },
        path: 'arac_getir', /* the path to the view in Drupal */
        row_callback: 'arac_getir_list_row',
        empty_callback: 'arac_getir_list_empty',
        attributes: {
          id: 'arac_getir_view',
          'data-filter': 'true',
        }
      };
      return content;
    }
    catch (error) { console.log('arac_getir_page - ' + error); }
  }

  /**
   * The row callback to render a single row.
   */
   function arac_getir_list_row(view, row) {
    try {
      return l(row.title, 'node/' + row.nid) + row.field_kart_no + 
      flag_quick_link(
        'ara_getir',
        'node',
        row.nid,
        parseInt(row.flagged) ? true : false
        );
    }
    catch (error) { console.log('arac_getir_list_row - ' + error); }
  }

  /**
   *
   */
   function arac_getir_list_empty(view) {
    try {
      return t('Kart bulunamadı');
    }
    catch (error) { console.log('arac_getir_list_empty - ' + error); }
  }
0

You could first create a custom form: http://docs.drupalgap.org/7/Forms/Creating_a_Custom_Form

Then in its submit handler build a Views Render Array and inject it into a waiting div placeholder element (markup widget) on the form:

http://docs.drupalgap.org/7/Views/Displaying_a_View/Views_Render_Array http://docs.drupalgap.org/7/Forms/Form_Elements/Element_Markup

Or have the submit handler go to a page with arguments: http://docs.drupalgap.org/7/Pages/Page_Arguments

Then that's page's page_callback could build a Views Render Array and use the search string as a contextual filter to the View.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.