form fields clear? - forms

i want to clear the fields of my form after the user has inserted the data in the database .I have provided a button for that but how to do that please tell me
Thanks
Ritz

<input type='reset' id='btnResetFields' value='Clear Fields' />
sets the form elements back to their initial state when the form was first loaded. [Web Application]

If it is a web application you can use reset button:
<input type="reset" value="Reset values" />

Related

Possibility of a Form without a Submit Button

hope You all have a great day.Here I'm trying to create a form without submit buttons,but when press enter on the text-box the whole text-box gonna hide.why is this is happening?,is it actually possible to create a form without a submit button or is that is a mandatory thing?,thanks for Your valuable time.
<form >
<input type="number" name="cbarcode" id="cbarcode" autofocus/>
</form>
When you hit 'enter' it submits the form.
I believe this is a natural part of a 'form' behavior for accessibility. Input inside of a form is meant to be data the user sends or inserts somewhere which is likely the reasoning behind this.
You can add to the Html form onsubmit="return false" or return preventDefault() as an event handler / function with other handling code you may want to provide.
Try this:
<form onsubmit="return false;">
<input type="number" name="cbarcode" id="cbarcode" autofocus/>
</form>

fluid template and TYPO3: Form inside a form - submit doesn't work anymore

If i insert a form inside a form, the submit button in the "outer" form doesn't work anymore.
Short code example:
<f:form action="update" name="examples" object="{examples}" >
<f:for each="{examples}" as="example"
<f:form.textfield property="name" value="" />
<f:form.checkbox property="checked" value="1" checked="0" /><br />
<f:form action="delete" name="example" object="{example}" >
<f:form.submit value="delete" />
</f:form>
<f:form.submit value="update" />
</f:form>
So basically (this is an extremely simplified version of my real life project) i want to be able to change the values of the textfield and checkbox which are then passed to the updateAction. The for each loop just generates multiple entries and therefore multiple forms just containing the delete button for that specific object so to speak. I can address these objects by __identity and they can be deleted by the button next to them, that's not the problem.
But the submit button for update doesn't work anymore if i put other forms with their respective submit buttons into this form.
Is there any solution for that?
Forms inside forms do not work (and is not proper HTML either).
Longer version that answers the question you didn't ask: to achieve your goal here, use f:link.action to create a link to the delete controller action with your {example} object as parameter. Then style that link to look like a button if you wish.
Completely unrelated from TYPO3 or Fluid you should know that nesting forms is not allowed.
However, at least the editing part of your code can be made valid with a single form:
<f:form action="update" name="examples" object="{examples}" >
<f:for each="{examples}" as="example" iteration="i">
<f:form.textfield property="{i}.name"/>
<f:form.checkbox property="{i}.checked" value="1"/>
</f:for>
<f:form.submit value="update"/>
</f:form>
With this set up it is not possible to also have a delete action in place since you'd need a submit button which does two things:
Request the delete action:
<f:form.button type="submit" name="action" value="delete">Delete</f:form.button>
Point at the entity to address:
<f:form.button type="submit" name="example" value="{example}">Do something with {example.title}</f:form.button>
You should add a separate view for editing single example objects instead. The current view then becomes a list with links to that edit view. In that view your form object becomes a single example which allows you to add two submit buttons for each action.

How to detect which submit button was clicked when the names are unknown?

I know how to detect which submit button was clicked when I know the name values of each of the buttons. But what if the names are dynamic or defined by another component?
For example, here I can simply check the POST data from this <form> for either alpha or bravo:
<form>
<input type="submit" name="alpha" value="Alpha">
<input type="submit" name="bravo" value="Bravo">
</form>
But that's only because I know I should be looking for those names.
Is there a best practice for handling this type of situation? (Perhaps by rendering an element <input type="hidden" name="submit-button-names" value="dynamic_name1|dynamic_name2|etc">.) I would like a solution that doesn't require JavaScript.
Presuming you have control over the JSP displaying these buttons, just prefix the button names with a string you can look for in the POSTed data. For example prepending "dynamicbutton_" to all of the names like this
<form>
<input type="submit" name="dynamicbutton_alpha" value="Alpha">
<input type="submit" name="dynamicbutton_bravo" value="Bravo">
</form>
Then in your Servlet, look for values with this prefix by calling ServletRequest.getAttributeNames()
You could write a custom tag to set the different inputs to your form based on a list of parameters you give to the tag.
You would end up with the HTML looking something like this:
<form method="POST" action="SelectColour.do">
<p>Select your favorite colour: </p>
<formTags:select name='colour' size='1' optionsList='${applicationScope.colourList}'/>
<input type="SUBMIT" value="Click here to submit">
</form>
Here's a decent guide to creating custom tags.

Passing value outside form

I need to get the value from outside the form. My gsp looks like this
<g:textField name="email" value="${someInstance?.email}"/>
<input type="button" id="checkEmail" class="button" value="Validate" onclick="checkEmail()"/>
<span id="responseDiv"></span>
<g:form action="save">
someCode
<g:submitButton disabled="true" style="color:#999999;" class="save" name="save" action="save" id="saveButton" value="${message(code: 'default.button.save.label', default: 'Submit')}"/>
</g:form>
First, to check if an email is in use, click button (id="checkEmail") and onclick goes to js code checkEmail() which has remoteFunction that updates responseDiv. After that, user enters information to the form, and user clicks submitButton. When that submit button is clicked, I would like my gsp to send email value along with other information to the controller. Any suggestion?
Thanks in advance.
Easy, put the input inside the form.
If that isn't an option for some reason, use the callback to update a hidden field inside the form with something like $("#hiddenEmail").val(emailAddress);
PS. I like how you gave a span an id of responseDiv :)

How do I keep track of when what is the text entered in the form when the user navigates away from the page?

I have a piece of code like this.
<form method="get" action="{$self}" name="addcommentform">
<textarea title="{$enterComment}" name="comment" class="commentarea" </textarea>
<input class="Button" type="submit" value="{$postComment}" />
</form>
How do I keep track of when what is the text entered in the form's textarea when the user navigates away from the page? I want to prompt the user with a warning message so he/she doesn't lose the text.
Thanks.
You could use the javascript/jquery blur event, and if the user hasn't clicked the desired button have it display the form values. This might help JQuery Blur Validation Problem
Stu
Take a look at this Javascript code snippet:
http://www.boutell.com/newfaq/creating/disableclose.html
This takes advantage of the window's onbeforeunload event which fires when the user is about to leave the page.