signalpoint / DrupalGap

An application development kit for Drupal websites.
https://www.drupalgap.org
GNU General Public License v2.0
232 stars 185 forks source link

Form hidden after page reload #1009

Closed jsbriantes closed 6 years ago

jsbriantes commented 6 years ago

I have created a custom form to search products (following docs example). I want this form to stay in the header (as in Ebay or Amazon app). Although you go to other page, the form should always be on the top. I have create a custom module and I have added a function mymodule_block_info where I added a new block:

function mymodule_block_info() {
    var blocks = {};

    blocks['searchblock'] = {
        delta: 'searchblock',
        module: 'mymodule'
    };

    return blocks;
}

The block_view function:

function mymodule_block_view(delta, region) {
    var content = '';

      // Search form
    if (delta == 'searchblock') {
        content = drupalgap_get_form('mymodule_searchblock_form');
    }

    return content;
}

In settings.js I have added the new block to the header region:

header: {
    main_menu: { },    
    searchblock: { }    
  },

It works good and the form is functional. But if you navigate to a page and then go back, the form disappears from then page. Every time you go to a page that was previously visited, the form disappears. I have tried adding {reloadPage:true} to the link, but without success. As I have checked with debugger, the form is totally removed from the original page. How could I do it?

signalpoint commented 6 years ago

@jsbriantes Since DrupalGap 7 isn't an SPA, we have to append use a unique form id each time it is rendered. In you're form builder function try something like this:

function my_custom_form(form, form_state) {
  form.id += '_' + user_password();
}

This is a design flaw in DrupalGap 7, but hopefully this workaround will work for you.

The user_password() function just returns a random string.

jsbriantes commented 6 years ago

Thanks very much. I assumed that It was the problem due some test I did. I'll put different id as you said.