-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
416e832
commit 151a321
Showing
8 changed files
with
237 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ import grails.artefact.TagLibrary | |
import grails.config.Config | ||
import grails.core.support.GrailsConfigurationAware | ||
import grails.gsp.TagLib | ||
import grails.web.mapping.LinkGenerator | ||
import groovy.transform.CompileStatic | ||
import groovy.util.logging.Commons | ||
import org.grails.plugins.web.GrailsTagDateHelper | ||
|
@@ -30,7 +31,6 @@ import java.text.DateFormatSymbols | |
import org.grails.core.artefact.DomainClassArtefactHandler | ||
import org.grails.encoder.CodecLookup | ||
import org.grails.encoder.Encoder | ||
import grails.web.mapping.LinkGenerator | ||
import org.grails.buffer.FastStringWriter | ||
import org.grails.web.servlet.mvc.SynchronizerTokensHolder | ||
import org.grails.buffer.GrailsPrintWriter | ||
|
@@ -384,7 +384,7 @@ class FormTagLib implements ApplicationContextAware, InitializingBean, TagLibrar | |
* @attr action the name of the action to use in the link, if not specified the default action will be linked | ||
* @attr controller the name of the controller to use in the link, if not specified the current controller will be linked | ||
* @attr id The id to use in the link | ||
* @attr url A map containing the action,controller,id etc. | ||
* @attr url A map containing the action, controller, id etc. | ||
* @attr name A value to use for both the name and id attribute of the form tag | ||
* @attr useToken Set whether to send a token in the request to handle duplicate form submissions. See Handling Duplicate Form Submissions | ||
* @attr method the form method to use, either 'POST' or 'GET'; defaults to 'POST' | ||
|
@@ -403,7 +403,7 @@ class FormTagLib implements ApplicationContextAware, InitializingBean, TagLibrar | |
* @attr action the name of the action to use in the link, if not specified the default action will be linked | ||
* @attr controller the name of the controller to use in the link, if not specified the current controller will be linked | ||
* @attr id The id to use in the link | ||
* @attr url A map containing the action,controller,id etc. | ||
* @attr url A map containing the action, controller, id etc. | ||
* @attr name A value to use for both the name and id attribute of the form tag | ||
* @attr useToken Set whether to send a token in the request to handle duplicate form submissions. See Handling Duplicate Form Submissions | ||
* @attr method the form method to use, either 'POST' or 'GET'; defaults to 'POST' | ||
|
@@ -420,16 +420,16 @@ class FormTagLib implements ApplicationContextAware, InitializingBean, TagLibrar | |
|
||
def linkAttrs = attrs.subMap(LinkGenerator.LINK_ATTRIBUTES) | ||
|
||
writer << "<form action=\"" | ||
writer << '<form action="' | ||
|
||
// Call RequestDataValueProcessor to modify url if necessary | ||
def link = createLink(linkAttrs) | ||
if (requestDataValueProcessor != null) { | ||
link= requestDataValueProcessor.processAction(request, link, request.method) | ||
link = requestDataValueProcessor.processAction(request, link, request.method) | ||
} | ||
|
||
writer << link | ||
writer << "\" " | ||
writer << '" ' | ||
|
||
// if URL is not null remove attributes | ||
if (attrs.url == null) { | ||
|
@@ -518,10 +518,13 @@ class FormTagLib implements ApplicationContextAware, InitializingBean, TagLibrar | |
* @attr value REQUIRED The title of the button and name of action when not explicitly defined. | ||
* @attr action The name of the action to be executed, otherwise it is derived from the value. | ||
* @attr disabled Makes the button to be disabled. Will be interpreted as a Groovy Truth | ||
* @deprecated As of 7.0.0, use {@link #formActionSubmit} instead | ||
* | ||
*/ | ||
@Deprecated(since = '7.0.0') | ||
Closure actionSubmit = { attrs -> | ||
if (!attrs.value) { | ||
throwTagError("Tag [actionSubmit] is missing required attribute [value]") | ||
throwTagError('Tag [actionSubmit] is missing required attribute [value]') | ||
} | ||
|
||
attrs.tagName = "actionSubmit" | ||
|
@@ -548,6 +551,70 @@ class FormTagLib implements ApplicationContextAware, InitializingBean, TagLibrar | |
out << '/>' | ||
} | ||
|
||
/** | ||
* Creates a submit button using the `formaction` attribute to submit to a different action than the form. | ||
* The action will be generated by the various link attributes.<br/> | ||
* | ||
* <g:formActionSubmit action="myaction" value="Submit"/><br/> | ||
* <g:formActionSubmit controller="myctrl" action="myaction" value="ButtonName"/><br/> | ||
* | ||
* @attr id the id attribute of the formActionSubmit tag | ||
* @attr value the button's show value | ||
* @attr action The name of the action to use in the link, if not specified the default action will be linked | ||
* @attr controller The name of the controller to use in the link, if not specified the current controller will be linked | ||
* @attr namespace The namespace of the controller to use in the link | ||
* @attr plugin The name of the plugin which provides the controller | ||
* @attr id The id to use in the link | ||
* @attr fragment The link fragment (often called anchor tag) to use | ||
* @attr mapping The named URL mapping to use to rewrite the link | ||
* @attr method The HTTP method specified in the corresponding URL mapping | ||
* @attr params A map containing URL query parameters for the link | ||
* @attr url A map containing the action, controller, id etc. | ||
* @attr uri A string for a relative path in the running app. | ||
* @attr relativeUri Used to specify a uri relative to the current path. | ||
* @attr absolute If set to "true" will prefix the link target address with the value of the grails.serverURL property from Config, or http://localhost:<port> if no value in Config and not running in production. | ||
* @attr base Sets the prefix to be added to the link target address, typically an absolute server URL. This overrides the behaviour of the absolute property, if both are specified. | ||
* @attr event Webflow _eventId parameter | ||
*/ | ||
def formActionSubmit = { Map attrs -> | ||
if (!attrs.value) { | ||
throwTagError('Tag [formActionSubmit] is missing required attribute [value]') | ||
} | ||
|
||
def elementId = attrs.remove('id') | ||
|
||
// the following attributes are reserved because this tag must be of type `submit` and the `formaction` attr | ||
// will be generated by the link attributes. | ||
attrs.remove('type') | ||
attrs.remove('formAction') | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jdaugherty
Author
Contributor
|
||
|
||
out << '<input type="submit" formaction="' | ||
|
||
Map linkAttrs = attrs.subMap(LinkGenerator.LINK_ATTRIBUTES - 'elementId') | ||
|
||
// Call RequestDataValueProcessor to modify url if necessary | ||
String link = createLink(linkAttrs) | ||
if (requestDataValueProcessor != null) { | ||
link = requestDataValueProcessor.processAction(request, link, request.method) | ||
} | ||
|
||
out << link | ||
out << '" ' | ||
|
||
attrs.keySet().removeAll(LinkGenerator.LINK_ATTRIBUTES) | ||
if (elementId) { | ||
attrs['id'] = elementId | ||
} | ||
|
||
booleanToAttribute(attrs, 'disabled') | ||
|
||
// process remaining attributes | ||
outputAttributes(attrs, out, false) | ||
|
||
// close tag | ||
out << '/>' | ||
} | ||
|
||
/** | ||
* Creates a an image submit button that submits to an action in the controller specified by the form action. | ||
* The name of the action attribute is translated into the action name, for example "Edit" becomes | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
If the formAction attribute were specified, do you think a warning should be logged letting the developer know that it is being ignored?