Setting Date text object with correct formatting string - asp.net-mvc-4

I can not figure out the secret format string to get my time displayed into a time text box. The time is stored in the database in this format '10:30 AM' DeliveryTime is defined as a string in the database. I have tried various versions similar to this below to no avail. Please help.
<input type="time" id="DeliveryTime" name="DeliveryTime" class="form-control" value="#Model.DeliveryTime.ToString("hh:mm tt")">

Looking at the format of the value in the database (10:30 AM) and the format you are trying to use: hh:mm tt, they are the same.. so all you need to do is display it directly:
<input type="time" id="DeliveryTime" name="DeliveryTime" class="form-control" value="#Model.DeliveryTime">
Or am I missing something here?

Related

How to use scriptAll to grab all values when the intended value is not text type

I have a page with multiple textboxes and dropdowns with values that I am trying to validate. The values in them will be dynamic in each run.
The HTML looks something like:
<input readonly="readonly" class="form-control valid" data-val="true" data="ABC" aria-invalid="false" xpath="1">
What I want to do is grab the value of "data" for each textbox. I have used scriptAll before in such a case when I was grabbing text by using innerText. However, that won't work with a regular value such as in the HTML above.
I did try one solution that worked:
driver.value(//input[#data])
However, that just grabs the first textbox value, is there a way I can combine scriptAll with driver.value? OR would I be better off doing some JS here?
Thank you in advance!
Yes, refer the docs for scriptAll(): https://github.com/karatelabs/karate/tree/master/karate-core#scriptall
Use whatever JS works to get an attribute value. Haven't tried, but this should work, you get the idea:
* def list = scriptAll('input', "_.getAttribute('data')")

Trying to click labels inside input

html code:
<input id="19eb0353-6208-4baa-8f89-f7af0a6edb91" type="date" placeholder="Date of Birth" value="" name="dateOfBirth" data-componentname="dateOfBirth" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" data-ddlabel="dd" data-mmlabel="mm" data-yyyylabel="yyyy">
ID is dynamic
Trying to enter the day month and year but not sure how to write it
I know this is the data but cant find anything on selecting these specific labels inside the input
data-ddlabel="dd" data-mmlabel="mm" data-yyyylabel="yyyy"
Tried Xpath, css selector but the ID is dynamic
You can use the below css.
input[type='date']
or the below xpath
//input[#type='date']
Screenshot:
when registration page opens (after clicking join now), you can use xpath like "//select[#id='nike-unite-date-id-mm']" to select date, month and year separately (like dropdown).
OR
you can directly point to specific date using xpath
"//select[#id='nike-unite-date-id-mm']//option[contains(text(),'10')].click()"
this will directly select the date, similarly can be done for months and year by changing #id
Please use below code.
I have tested, it worked for me.
driver.findElement(By.xpath("//input[#type='date']")).sendKeys("04/04/1989");
Please let me know if you face any error.
You can try this (example using python):
from selenium.webdriver.support.ui import Select
month = Select(driver.find_element_by_id('nike-unite-date-id-mm'))
month.select_by_visible_text("08")
day = Select(driver.find_element_by_id('nike-unite-date-id-dd'))
month.select_by_visible_text("21")
year = Select(driver.find_element_by_id('nike-unite-date-id-yyyy'))
month.select_by_visible_text("2019")
And use Select Method like this:
<option value="01"> 01 </option>
^^
select_by_visible_text("01")
<option value="01"> 01 </option>
^^^^^^^^^^
select_by_value("01")

WebMatrix - US date/time format proving to be an issue

I am creating a UK-based website, so users on my site will typically be used to the format dd/mm/yyyy. I have created a datepicker for the users to use, and it works fine, until i pick the 13th day, (13/10/2013). I'm guessing the database is seeing this as a US date, and thus there are not 13 months in a year.
What do i need to do to my code to convert this to the correct format, or change my databse to use UK format? What's easiest?
if(IsPost){
var dateis = Request["date"];
var insert = "INSERT INTO TestTable (testdate) VALUES (#0)";
var qinsert = db.Execute (insert, Request["date"]);
}
}
<div class="container">
<h1>Bootstrap Datepicker</h1>
<form method="post">
<div class="input-append date" id="dp3">
<input class="span2" name="date" size="16" type="text" value="">
<span class="add-on"><i class="icon-th"></i></span>
</div>
<button class="btn btn-success" type="submit" value="Submit"/>Submit</button>
</form>
</div>
<script type="text/javascript">
$('#dp3').datepicker({
format: "dd/mm/yyyy",
autoclose: true,
todayHighlight: true
})
</script>
I personally use the format d MM yyyy for datepickers (eg '14 November 2013'). It takes up more space, but to me it's more readable and completely sidesteps the dd/mm/yyyy vs mm/dd/yyyy issue.
If you want to keep it the way it is, as long as your development machine and server machine is correctly configured for UK times, you can use the AsDateTime() extension method which should resolve the issue.
var qinsert = db.Execute (insert, Request["date"].AsDateTime());
As Mike points out in another answer, this isn't best practise though - having code that is reliant on server setup and the like can easily come back to haunt you.
Generally, you are best advised storing dates in yyyy/mm/dd hh:mm:ss format. That way there is no problem with regional variations. Also, if your app is global, you might want to consider using UTC so that there are no issues with varying server times.

HTML text field not displaying decimal places of SQL money value

I have a text field who's value is populated from a SQL recordset (below).
<input name="txtAmount" id="txtAmount" type="text" size="10" maxlength="10" value="<%=RS("Amount")%>">
In the SQL table, the Amount field (which is a money data type) is inserted correctly, as 5.00 However, in the web page, it displays only as 5 (i.e. the decimal places are missing). Anyone know why this might be and how I can get the decimal places to display in the field? Thanks!
If you don't want the dollar sign, use
value="<%=FormatNumber(RS("Amount"),2)%>"
Applying formating will do the trick:
<input name="txtAmount" id="txtAmount" type="text" size="10" maxlength="10"
value="<%=FormatCurrency(RS("Amount"), 2)%>">
If your code is in .NET, you can use
<%= String.Format("{0:0.00}", RS("Amount")) %>

How can I set the initial value of a dijit.form.DateTextBox to today?

I've created a DateTextBox like:
<input dojoType="dijit.form.DateTextBox" constraints="{max: Date.now()}" id="startDate" />
When the page loads there is no value in the field. I would like the value to default to today. Is there a way to handle this? I know I could use the "value" attribute and set it in the declaration, but that only allows me to put a static date in the field, not a dynamic date.
It would also be good if the solution works with a form reset too.
Thanks for the help!
The parser supports the "now" keyword, so you could do:
<input dojoType=dijit.form.DateTextBox value="now">
Of course, for programmatic creation you would simply do:
new dijit.form.DateTextBox({value: new Date()})
Your solution:
<input dojoType=dijit.form.DateTextBox value="now">
If you want to make the date other than today:
<input dojoType=dijit.form.DateTextBox value="now" constraints="{max: new Date()}">