How do I submit data with Dojo DateTextBox after selecting a date - dojo

I'm trying to make a DateTextBox that submits data once a date is selected. To do that I have this code: <form action="timecard/setViewDate" method="post" id="timespan" dojoType="dijit.form.Form">
<input type="text" name="calendar" value="2009-09-28" id="calendar" dojoType="dijit.form.DateTextBox" onchange="doTimechangeSubmit" />
</form> and the onchange function is: function doTimechangeSubmit()
{
var thisdialog = new dijit.Dialog({ title: "Please Wait...", content: "We are wasting some time.", id: 'stupidWasteOfTime'});
dojo.body().appendChild(thisdialog.domNode);
thisdialog.startup();
thisdialog.show();
setTimeout("dojo.byId('timespan').submit();",1000);
dojo.byId('timespan').submit();
}
I have this function because without waiting a bit the value I receive is the date the widget starts with. I hate this and I'm just waiting for a slow response to break it.
My want is to hook the submit function in a place that guarantees I get the value the user actually selected. Anybody have any ideas?

This is fixed in Dojo 1.4. Refer to ticket #9566.

Change dojo.byId('timespan').submit(); to dijit.byId('timespan').submit();
For an explanation read this.

Related

TestStack.Seleno TickCheckbox not working

I have 2 forms that I am testing using TestStack.Seleno. Both forms have a checkbox that is mandatory. The first form has (including the checkbox) 5 fields. I can use TestStack.Seleno to create a passing test with valid data. I set the checkbox like this:
Input.TickCheckbox(f=>f.Accept,form.Accept);
On my other form which has 10 or so fields, when I try to set the checkbox to be ticked (using the same code) nothing happens. However when I try
var acceptCheckBox = Find.Element(By.Name("Accept"),new TimeSpan(0,0,0,50));
if (form.Accept)
{
acceptCheckBox.Click();
}
I get error "Element is not currently visible and so may not be interacted with"
Element is clearly visible and is not injected in using javascript.
I am using latest version of TestStack.Seleno from github.
Any ideas?
So I have managed to figure out what the issue is and have a work around, however I cannot explain why it works on the other form. The mandatory Accept field has html generated by mvc that looks like
<div>
<input class="check-box" data-val="true" data-val-mustbetrue="The Accept our field is required" data-val-required="The Accept our field is required." id="Accept" name="Accept" type="checkbox" value="true"><input name="Accept" type="hidden" value="false">
<label for="Accept">
Accept our Please accept our Terms and Conditions
</label>
<span class="field-validation-valid" data-valmsg-for="Accept" data-valmsg-replace="true"></span>
</div>
So you have the checkbox and hidden field both with id Accept, I suspect in code seleno is picking up the hidden field and setting value, so I updated my code todo
var acceptCheckBox = Find.Element(By.CssSelector("#Accept.check-box"));
acceptCheckBox.Click();
Now everything works.
Ismail

Calling Post method using HTML.ActionLink

I have read multiple posts on similar issue but did not work.
I have fixed footer buttons and facing issue in calling "Post" version Edit action in Project controller. Here is what I'm trying to do
Let me know if question needs further explaination.
(I tried using Ajax.ActionLink which is suggested in multiple posts too but did not work out.
Similar Question
Finally I managed to fix it by some workarounds. Posting solution here to help someone.
Like I said earlier, I tried using Ajax.ActionLink but I was not able to achieve the same. Instead I looked for Calling Form Submit action from outside of form that's what I actually need here.
Form: Name your Form something, say "editProjDetailsForm"
#using (Html.BeginForm(null, null, FormMethod.Post,
new { #class = "form-horizontal",
name = "editProjDetailsForm" }))
Footer: Call this method from the footer button.
<input type="button" onclick="document.editProjDetailsForm.submit();"
class="btn btn-primary"
value="Save Changes" />
I tried this one too in footer but it did not workout:
#Ajax.ActionLink("Save Changes", "Edit", new { id = Model.ProjectId },
new AjaxOptions { HttpMethod = "POST" })
Helpful Posts
Naming A form using Begin Form
Submit Button outside HTML.BeginForm
Submit Button outside HTML.BeginForm (another link)
ASP.net ActionLink and POST Method
Error in case you have parameterized constructor in ViewModel and
did not declare parameterless constructor
Display Issue if you are using bootstrap In footer I had one input type = button and one action link with class= button. Both nested in one btn-group but there height were appearing different as visible in following snapshot:
Fix: Found that it is a known issue and there is one suggested solution but did not work out much for me (i.e. for Internet Explorer).
input type=submit and anchor button in btn-group appear as different sizes
Solution: add .btn { line-height:normal!important; } or if you want to do only for a specific button lets say the above input button then do this:
<input type="button" onclick="document.editProjDetailsForm.submit();"
class="btn btn-primary"
value="Save Changes"
style="line-height:normal!important;" />

getelementsbyname not returning any value

I've spent all day reading tutorials but can't seem to find an answer to this basic question.
All I want to do is access the value of an input field. I've made a basic stub to try and teach myself. The desired behavior is that when I click the "submit" button, I should get an alert with the value of the number field "points". However, when I put the following code in my website, then click the submit button, nothing happens.
<script type="text/javascript">
function checknumber()
{
var testnumber=document.getelementsbyname("points").value;
alert(testnumber);
}
</script>
<input type="number" name="points" value="1">Points<br>
<input type="submit" onclick="checknumber();">
What am I doing wrong?
Incidentally, if I get rid of the line with "getelementsbyname" and change the script as follows:
function checknumber()
{
var testnumber="hello world";
alert(testnumber);
}
Then everything works fine, I get an alert popup with the text "hello world" exactly as expected.
Any help will be greatly appreciated.
Its because getElementsByName returns an HTMLCollection. So you have to use:
function checknumber()
{
var testnumber=document.getElementsByName("point")[0].value;
alert(testnumber);
}
or
function checknumber()
{
var testnumber=document.getElementsByName("point")[0].value;
alert(testnumber);
}
Here's the demo (click Run with JS, input any number and click the button; the alert will pop up).

Pass text box value to a dojo grid's query parameter

I am trying to pass the value in a text box as a query parameter in a dojo data grid and would like to get clarified on two questions listed below. The dojo grid initiates a call to the server with the query params to initiate a search and bring back results (that is diplayed on the data grid)
Is it possible to reload the gird based on the value in the text by invoking refresh (dijit.byId("mygrid").refresh
If yes, how can I pass the value of the text box as a query parameter to the data grid.
Listed below is my relevant code
function reload(){
dijit.byId("mygrid").refresh;
}
<div class="test">
<input id="searchParam" >
<button dojoType="dijit.form.Button" type="submit" onclick=reload()>
Search
</button>
</div>
<div dojoType="dojox.grid.DataGrid"
id="mygrid"
jsid="mygrid"
store="dojox.data.JsonRestStore"
target="<c:url value='members' />">
query="{
searchCriteria: ? TODO How to pass value of text box here?,
}"
rowsPerPage="1000"
autoWidth="true"
autoHeight="true"
selectionMode="single"
selectable="true"
errorMessage="Error loading data"
noDataMessage="<span class='dojoxGridNoData'>No members found.</span>">
</div>
You should be able do something like the following:
function reload() {
var val = dojo.byId('searchParam').attr('value');
dijit.byId("mygrid").setQuery({ propName: val });
}
You will need to properly build the query { propName: val }.

Safari resends same form after redirect

I am currently experiencing a bug that only occurs in the current version of Safari (5.1.5) and was wondering if anyone here could come up with any workarounds for it. I tested it in 5.1.2 and it worked fine there, I'm not sure about 5.1.3 and 5.1.4 as I don't have access to those releases.
The bug requires three pages, I'll show the source of them and then explain what is going on:
FirstPageWithForm.htm
<form id="theForm" action="ActionHandler.ashx" method="post">
<input type="hidden" name="differentField" value="1234"/>
<input type="hidden" name="sameField" value="1111"/>
</form>
<script type="text/javascript">
var theForm = document.getElementById("theForm");
theForm.submit();
</script>
SecondPageWithForm.htm
<form id="theForm" action="ActionHandler.ashx" method="post">
<input type="hidden" name="differentField" value="5678"/>
<input type="hidden" name="sameField" value="1111"/>
</form>
<script type="text/javascript">
var theForm = document.getElementById("theForm");
theForm.submit();
</script>
ActionHandler.ashx
public void ProcessRequest(HttpContext context)
{
var referrer = context.Request.UrlReferrer;
var differentField = context.Request["differentField"];
context.Response.Write(differentField);
if (differentField == "1234")
{
if (referrer.ToString().Contains("Second"))
context.Response.Write("Failure");
else
{
context.Response.Redirect("SecondPageWithForm.htm");
}
}
else
context.Response.Write("Success");
}
As you notice both forms have the same field name but one of the fields has a different value. However, in Safari when this code is run, the value "1234" is sent as differentField instead of "5678". I do not believe this bug has anything to do with .NET but I don't have an easy way to test another language to be sure about that.
Things I already tried:
Putting the form submission code in a function and then calling that.
Requiring Jquery and calling it in the $(document).ready() function.
Putting the function call in a setTimeout().
Replacing the function with a button that I press.
Copying the Handler and sending the second form to the copy instead.
Every single one of these methods had the same effect, which is to print "Failure" instead of Success.
I will be filing this bug on the Safari forums (I don't have an Apple Developer account and it's not working to create a new one at the moment), but I was hoping that someone could help me come up with a suitable workaround for this problem until they fix it.
EDIT: The Safari forum bug report: https://discussions.apple.com/thread/3921507
NicolasIgot on my safari forum figured out a solution to my problem.
I just added autocomplete="off" to the form tag on the second form and everything started working again. I haven't tried it on my real problem, but it works on my simple test case, so I have confidence in it.