WatiN - Find Form By Element - watin

I have a sample webpage:
<form action=blabla.php methog=post>...</form>
<form action=blabla.php methog=post>...</form>
<form action=blabla.php methog=post>...</form>
<form action=blabla.php methog=post>...</form>
<form action=blabla.php methog=post><textarea name="data"></textarea><input type="submit"></form>
I want to set textarea and submit last form. It's OK, I can find the text area with Find.ByName("data") syntax.
But how can I find the corresponding form for the "data" element?
I don't want to use
browser.Forms[index]
Is there any way how I can find a corresponding form to be able to make Form.Submit() ?

After you get your text area (for eg in a var textArea) just use Ancestor()
Form myForm = textArea.Ancestor("form");
.Ancestor(...) resembles .Parent in ASP.NET

Related

Laravel confused if I should use <form> tag or not when doing a ajax put request

I am making a simple put request to my app backend using axios.put();
This all works, I have a button that is binded to vue like #click="submitForm"
However looking around I see that some people still wrap their input fields in forms like those:
<form method="POST" #submit.prevent="onSubmit" action="{{ route('someRoute') }}" id="form-submit">
{{ method_field('PUT') }}
{{ csrf_field() }}
Even if I dont use a form like the one above I get the same result when calling my ajax put request.
Laravel allready adds csfr headers to axios by default in resources/assets/js/bootstrap.js
So is there any reason I still should wrap my inputs in a form like above?
Thanks
Your ajax request doesn't matter if you do your inputs in form tags or not, because the request still sends and receives data from a server.
I would use a form tag because everybody can read the markup much easier and it could be usefull for writing less code in javascript - one example
<form action="" method="">
<div class="form-group">
<label class="control-label">Input</label>
<input type="text" name="input" />
</div>
</form>
$(document).ready(function() {
$('#some-form').on('submit', function() {
var data = $(this).serialize();
... do whatever you want (like ajax call) ...
return false;
});
);
You're using an Ajax request, in which case a standard "form submit" would get prevented. Putting a form around it is not obligatory, especially if you use a button element, which is not a classic form element anyway.

Set visibility of form input in thymleaf using th:if

I am new to thymeleaf and I have this problem.
I have a form to add and edit products.
From the controller I set request mapping to access this form view using
#RequestMapping("/products/add")
and
#RequestMapping("/products/edit/{id}")
I have a field in products ,Date endPromotion.
I want this input block that has endPromotion field to be shown only in edit mode.
How can I do that using thymleaf condition?
i tried somthing like
<div th:if="${|/products/{action}(action='edit')|}"> .. valid html code ... </div>
but it doesn't work
This should do the trick
<div th:if="${#strings.contains(#httpServletRequest.requestURI, '/products/edit/')}">
some content
</div>

Required help on javascript

I have this piece of javascript code
<script language="javascript">
function editRecord(email){
window.open('CompleteProfileDisplay.jsp?email='+email);
f.submit();
}
</script>
My question is how to hide the email value in address bar while calling CompleteProfileDisplay.jsp page through window.open function.One more thing CompleteProfileDisplay.jsp accepting the email value as request.getParameter method.Please help me if anybody is having idea.
The open() method takes a second name parameter which you can use as the target of a post, so you can create a hidden form with a target, open about:blank with a the target name and submit that form.
Or you can have a form that submits to the special '_blank' target which also opens a window. Similarly you programmatically fill and submit the form.
Edit: I said '_new' which is wrong....
You can follow this outline to accomplish your goal:
Create a small form within your HTML, with its action property set to CompleteProfileDisplay.jsp, containing an input field named email, with a target of _blank, and a method of post.
Have your function set the value of the email input field of this form to the given email address and submit the form.
A popup window will open containing the same results as your original request, but the data (email address) will be submitted as a POST request without being visible in the URL.
Like this:
<!-- make sure this form isn't nested with another form in your page -->
<form action="CompleteProfileDisplay.jsp" target="_blank" method="post">
<input type="hidden" name="email" id="hiddenemail" />
</form>
<script>
function editRecord(email){
var e = document.getElementById('hiddenemail');
e.value = email;
e.form.submit();
}
</script>
(Your question does not show that you are customizing the popup window's appearance in any way, so I am not considering that in my answer.)

ASP.NET Razor - Unencoding Value

I am working on a form using the new Razor view engine, and am having an issue with a form field having an encoded value. I have the following code on my form:
<form id="handout" method="post" class="padded_form" enctype="multipart/form-data"
action="#Url.Remarketing().HandoutNew(Model.Inspection.InspectionId, Request.QueryString[QueryStringParamConstants.RedirectURL])">
<h2>Handout Options</h2>
<li>
#Html.Label("handout.Price", "Price")
#Html.TextBox("handout.Price", Model.Handout.Price)
</li>
where price is a decimal value. If I enter say "1,000" on the form, the value posted is: "&handout.Price=1%2c000" and the Price property on my entity does not get populated.
Is there a way to not encode this value when the form is posted?
Thanks.
You would have to use client-side javascript to normalize the value an remove any formatting characters.
Alternatively you could implement your own IValueProvider that could perform the conversion on the server before the model is databound.

JQuery for Push-down form

Is there a JQuery plugin that allows me to 'unhide' a form by after clicking a link? Like I have an invite link that can take me to a one text field form for an email address but I want this form to just drop down (pushing the rest of the content down also) and shows the form to submit the email. If you guys can think of a JQuery plugin that lets me do this, please let me know
Edit:
So I did this
<div class='add-link'>
<div id='invite_link'><a href=''>Invite User</a></div>
<div id='invitation_form'>
<form>
<input type='text'/>
</form>
</div>
</div>
and my jquery looks like
<script type="text/javascript">
$(function()
{
$("table").tablesorter({sortList:[[0,0],[2,1]], widgets: ['zebra']});
$('#invitation_form').hide();
}
);
$('#invite_link').click(function() {
$('#invitation_form').slideDown();
});
Do you guys see any error that causes the form not to slide down. It hides the form when the page loads but when I click the link it is not sliding down.
$('a.mylink').click(function() {
$('#MyForm').slideDown();
});
I don't think you need a jQuery plugin for this. The base jQuery library should be sufficient.
$('#showFormLink').click(function () {
$('#form').slideDown();
});
If you're looking for animation, that's possible as well by passing in a duration argument to slideDown.
Take a look at the jQuery show documentation.

Resources