Formatting date in domForm.toJson in dojo - dojo

In my Web Application i have changed my dijit/form/DateTextBox date format using constraints="{datePattern:'MM/dd/yyyy'}" attribute,
But when i call the form containing the dijit/form/DateTextBox using domForm.toJson the format is changed to yyyy/dd/MM
why?
How to solve it

Dijit/Form/DateTextBox is a dojo/widget not dom.
domForm.toJson access Dom's value not Dijit widget's get('value') function which gives you a formatted output as you expect.
To get correct value - Use Dijit/Form and then use form.get("value")
Dijit Form

Related

Unable to put date in <input type="date"> field in Firefox using Selenium

I am sending date of birth to an input element using selenium, data is getting entered in Chrome and Edge but in firefox that input element has an inbuilt datepicker and I am not able to inspect that default datepicker (right click doesn't work on datePicker and couldn't find any code for it). The input element is not taking values and I can't get the html element so I'm unable to fill the field.
Can anyone help me with this?
For Firefox, the date format is yyyy-mm-dd , regardless placeholder. I read Flaburgan's comment in https://github.com/mozilla/geckodriver/issues/1070 and searched documents, tested okay.
WebElement dateOfBirth = driver.findElement(By.name("dob"));
dateOfBirth.sendKeys("2012-12-24");
You handle this issue with the following trick:
Change the input type from date to text using JavaScriptExecutor by Selenium
After changing the element type to text the change the date field by sending text with the same format needed to change value, use sendKeys("dd/mm/yyyy").
OR try to use Selenium Actions move to element and click.

How to identify webelement using partial attribute of id?

I have to find xpath for a textbox using id attribute. However, a portion of the attribute keeps changing every time I login to the application which I'm automating and the remaining portion remains unchanged. PFB example -
Attribute ------> id="StringJob_value_1102199569"
Here, the numeric value changes during every login and the portion "StringJob_value" remains unchanged.
Hence, is there any way in selenium to only use the constant portion of the attribute to identify the web element(Text Box)?
Try the following xpath:
//*[contains(#id, 'StringJob_value_')]

How to set string to datetime widget?

The title is self explanatory. I am having difficulties setting a string value to a date time widget.
XCP has a build in function stringToDate
which i use in these examples...
1. stringToDate('5-5-2009')
2. stringToDate('05-05-2009')
3. stringToDate('5/5/2009')
But non of them work. What am I missing here ?
Also i set the value of the widget in the behaviors tab of the date widget.
If you are talking about Date-Time Input widget then you need to use dateToString not stringToDate.
I figured out the issue. It's dependent to the format in which you save your date to string value. If we save the Date-Time Input widget value in this format:
dateToString('12-12-2018', 'm-d-Y')
then doing a :
stringToDate(savedvalue) will work only when the format saved was 'm-d-Y'. It wasn't working before because i saved it as 'd-m-Y'.

Bootstrap DatePicker setDate method not updating calendar

I'm setting the value of a bootstrap datepicker by making use of the setValue method provided.
For example
tripToDatePicker.setValue(tripFromDatePicker.date);
But for some reason the calendar is not updated
'setValue' is replaced by 'setDate'.
Using a string as input for setDate can be tricky. It has to match with the dateformat, else you can get unexpected results. It is more safe to create a 'new Date(y,m,d)' from your input, e.g. new Date(2015,3,10) for '10 Apr 2015'. This will always work.
When using a date representation in seconds, e.g. 1428659901, then use 'new Date(value*1000)'. Note that datepicker will eat any value here, but only show the selected date in the calendar if hours, minutes and seconds are equal to 0. Took me a while to figure that out....
Edit:
http://www.eyecon.ro/bootstrap-datepicker/ is not much documented, you should try http://eternicode.github.io/bootstrap-datepicker/.
anyway the code below will work for you
$("#dp1").datepicker("update", "02-16-2012");
or
$("#dp1").datepicker("setValue", "02-17-2012");
where "#dpi" is the id of the text field on whcih datepicker is used.
After trying many things, I ended up using "update" method. The $("#dp1").datepicker("update", "02-02-2012") or $("#dp1").datepicker("update", "02/02/2012") works for me. Surprisingly no document about this method at author website. Thanks.

FormBlock Server Control in Ektron

I am working in Ektron 8.6.
I have a FormBlock Server Control in my Template Page,It is having a DefualutFormID of a valid HTML form from workarea.The form in the workarea have got few form fields and their corresponding values.
While the template page is rendering I need to GET those form field values and re-set them with some other values.
In which Page –Cycle event I should do this coding?
I tried this code in Pre-Render Event,but I am unable to GET the value there,but I am able to set a value.
I tried SaveStateComplete event as well,no luck.
String s=FormBlock1.Fields["FirstName"].Value;
If(s=”some text”)
{
// Re-set as some other vale.
FormBlock1.Fields["FirstName"].Value=”Some other value”;
}
In which event I can write this piece of code?
Page_Load works fine for changing the value of a form field. The default behavior is for the Ektron server controls to load their data during Page_Init.
The real problem is how to get the default value. I tried every possible way I could find to get at the data defining an Ektron form (more specifically, a field's default value), and here's what I came up with. I'll admit, this is a bit of a hack, but it works.
var xml = XElement.Parse("<ekForm>" + cmsFormBlock.EkItem.Html + "</ekForm>");
var inputField = xml.Descendants("input").FirstOrDefault(i => i.Attribute("id").Value == "SampleTextField");
string defaultValue = inputField.Attribute("value").Value;
if (defaultValue == "The default value for this field is 42")
{
// do stuff here...
}
My FormBlock server control is defined on the ASPX side, nothing fancy:
<CMS:FormBlock runat="server" ID="cmsFormBlock" DynamicParameter="ekfrm"/>
And, of course, XElement requires the following using statement:
using System.Xml.Linq;
So basically, I wrap the HTML with a single root element so that it becomes valid XML. Ektron is pretty good about requiring content to be XHTML, so this should work. Naturally, this should be tested on a more complicated form before using this in production. I'd also recommend a healthy dose of defensive programming -- null checks, try/catch, etc.
Once it is parsed as XML, you can get the value property of the form field by getting the value attribute. For my sample form that I set up, the following was part of the form's HTML (EkItem.Html):
<input type="text" value="The default value for this field is 42" class="design_textfield" size="24" title="Sample Text Field" ektdesignns_name="SampleTextField" ektdesignns_caption="Sample Text Field" id="SampleTextField" ektdesignns_nodetype="element" name="SampleTextField" />