When using the gmap3_tools api function gmap3_tools_add_map to add a map into a form, the map won't be displayed if there are validation errors. That's because the JS is added using drupal_add_js only.
In the salsa_entity (salsa_event) module, we are loading a map within a form but as soon as validation fails, the map's gone. Please add support to add the JS using '#attached' property on the form.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | use-js-attached-2097425-6.patch | 3.28 KB | s_leu |
| #4 | use-js-attached-2097425-4.patch | 3.41 KB | s_leu |
| #1 | use-js-attached-2097425-1.patch | 1.95 KB | s_leu |
Comments
Comment #1
s_leu commentedHere's a patch that makes enables calling code to pass a form and attaches the js to it, if a form is passed.
Comment #2
s_leu commentedThe related issue in salsa_entity is #2097431: Map on event page breaks on validation failure
Comment #3
berdirThat's a somewhat "creative" solution. Wondering if it would make more sense to add a new function that returns a render array and @deprecate this one. Easier to port to D8, where drupal_add_js() will go away.
Comment #4
s_leu commentedAdding a patch as which adds a separate function for attaching the js to forms, also did some refactoring to prevent redundant code.
Comment #5
berdirtype hint the function argument with array &$form, then the check here isn't necessary.
Drupal is intelligent enough to avoid duplicates. Even easier if it would be a library, but that's another topic.
In fact, when you think about caching, you want to ensure that each partial render array has all the information it needs to be displayed.
A cached form won't run this function again, if there would be two calls/forms, the second one would get an incomplete render array and might not render correctly.
Comment #6
s_leu commentedAdding the suggested changes
Comment #7
pivica commentedChecked patch from #6, looking good, committed to 7.x-1.x branch.
@s_leu, @Berdir thx for your work.