Closed (won't fix)
Project:
Arrange Fields
Version:
6.x-1.6
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
22 Feb 2012 at 13:03 UTC
Updated:
1 Jul 2013 at 16:07 UTC
A page on my site which contains a Webform with Arrange Fields fails the W3C validator test because of the presence of a style tag which is outside of head and doesn't have a type attribute.
To fix this I have changed the code between lines 852 to 876 inclusive of arrange_fields.module (inside the function arrange_fields_form_alter())
if ($GLOBALS["arrange_fields_editing"] != $form_id) {
// Meaning, we are not currently arranging this form. The user
// must actually be putting data into it on the node/edit page.
// Let's remove the extra
// styles around the various divs so that it looks more natural.
$css_markup .= "
.arrange-fields-container {
border: 0;
background: none;
}
.arrange-fields-container .draggable-form-item {
border: 0;
background-color: transparent;
}
";
}
// Now, add in our css markup and markup elements...
$form["arrange_fields_css_markup_and_elements"] = array(
"#value" => "<style>$css_markup</style>$markup_elements",
"#after_build" => array("arrange_fields_add_form_css_js"), // important if the form fails validation, we still get the CSS and JS added in.
);
to
if ($GLOBALS["arrange_fields_editing"] != $form_id) {
// Meaning, we are not currently arranging this form. The user
// must actually be putting data into it on the node/edit page.
// Let's remove the extra
// styles around the various divs so that it looks more natural.
$css_markup .= "
#$fid {
border: 0;
background: none;
}
#$fid .draggable-form-item {
border: 0;
background-color: transparent;
}
";
}
// Now, add in our css markup and markup elements...
drupal_set_html_head('<style type="text/css">' . $css_markup . '</style>');
$form["arrange_fields_css_markup_and_elements"] = array(
"#value" => $markup_elements,
"#after_build" => array("arrange_fields_add_form_css_js"), // important if the form fails validation, we still get the CSS and JS added in.
);
The changes made to the CSS selectors are to increase specificity as the dynamically generated styles are now output above the link to the arrange_fields.css stylesheet (I'm using a Zen sub-theme).
Could this, or something like it, please be added to a future release?
Thanks,
David
Comments
Comment #0.0
DaveyM commentedChanged whitespace on first line of code examples
Comment #1
richardp commentedSure, that all looks fine to me. I will put those changes in place for both the 6 and 7 branch.
Thanks!
Richard
Comment #2
richardp commentedActually-- scratch that (sort of).
I can still set the type of the style tag to text/css, and I can still use the $fid instead of the generic class, but I cann't use drupal_set_html_head.
The reason is because if your form fails validation (like you do not enter a required field), when the page reloads it's all wonky. This is because hook_form_alter doesn't get called a second time. Instead the form is just loaded from cache.
The other changes I am happy to include in the next release though ;)
Richard
Comment #3
richardp commentedOkay, this is now in the 6.x-1.6 release! I've also added similar code for 7.x
Thanks
Richard
Comment #4
DaveyM commentedHi Richard,
I think I may have come up with a work-around that uses the after_build callback. Changing lines 885-889 from
to
and lines 922-928 from
to
Seems to load the style tag into the head tag when the webform fails validation. Does it look ok to you?
Thanks,
David
Comment #4.0
DaveyM commentedAdded whitespace at beginning of code examples
Comment #5
richardp commentedInteresting approach! I like it. I will try to have this in the next release.
Thanks,
Richard
Comment #6
richardp commentedAfter some tinkering, I decided to leave the style tag as it was in 7x due to simplicity reasons.
Thanks
Richard
Comment #6.0
richardp commentedRemoved angle brackets used in explanation