SmartGwt DateItem useTextField=true - how to make text entry field UNeditable - gwt

Since I can't figure out how to solve my problem presented here I'm thinking for the moment at a temporary solution.
I have a smartgwt DateItem widget:
DateItem date = new DateItem("Adate");
date.setWidth(120);
date.setWrapTitle(false);
date.setAttribute("useTextField", true);
date.setAttribute("inputFormat", "yyyy/MM/dd");
date.setAttribute("displayFormat", "toJapanShortDate");
Because the attribute useTextField is set to true we can see the text entry field. How can I make this text entry field to be uneditable.
Actually I want to have only the possibility to choose the date from calendar and not to change it manually.
Resolved - the issue exposed above - thanks to #RAS user.
TextItem textItem = new TextItem();
textItem.setAttribute("readOnly", true);
date.setAttribute("textFieldProperties", textItem);
Related link
But I have now another issue (resolved - see here):
The date chooser won't show the date on the text field but Today's date.
For example, enter 30/05/2009 on the text field, go to another field, then come back on click on the date chooser and the selected day will be Today's date instead on June 30th, 2009. Which is the reason for this? Can this be solved?
Also let's say I let to the user to opportunity to manually modify the date - can I put some **validators on it?** (still need an ideea on this)
Thank you.

date.setEnforceDate(true);
http://www.smartclient.com/smartgwt/javadoc/com/smartgwt/client/widgets/form/fields/DateItem.html#setEnforceDate%28java.lang.Boolean%29

You have a lot of different validators. Depending on the context it must be possible to validate cardinality, relation to other data items, datatype(not only date time values) and relations to other external records.

Related

PowerApps - autofill date for newform

Using PowerApps, how can I get the current date to be autofilled into a new form?
Does the code go into the IconNewItem1 function from the parent BrowseScreen1?
NewForm(EditForm1);Navigate(EditScreen1,ScreenTransition.None)
as something like ...
BrowseGallery1.Selected.Date = Now
Or does the code go in the EditScreen1 / EditForm1 area as a rule?
Any guidance or suggestion would be appreciated.
You would do that in the form itself (or the date picker control of the form). Select the card that has the date value, and in the right-side pane select the 'Advanced' tab. You'll need to unlock the card to change the properties, and when you do, change the Default property of the card from
ThisItem.DateTimeColumn
to
If(EditForm1.Mode = FormMode.New, Now(), ThisItem.DateTimeColumn)
Where DateTimeColumn would be replaced with the name of the column in your data source, and EditForm1 would be replaced with the name of the form control.

Use localized date format with date picker in cakephp 3

I'm building a cakephp 3 app (cakephp v3.3.2 that is) and I have a problem getting dates displayed in the chosen locale (de_DE).
The database field in my example is invoice_date, which is of type DATE (stored in a mysql DB).
I want to use a date picker in the web page ("zebra_datepicker"), so in the view I use a single text entry field for the date instead of the three drop-downs that are displayed by default:
echo $this->Form->input('invoice_date', [ 'type' => 'text' ]);
To get the date displayed in the German format dd.mm.YY I changed the global locale setting to
ini_set('intl.default_locale', 'de_DE');
in config/bootstrap.php.
For testing, I created a new record in the database and set the invoice_date to 2016-09-02 (Y-M-D).
If I call the edit action of my controller now, I get a default value of 02.09.16 in the form, which is correct. But if I submit the form back, the database value of the field is changed into 2002-09-16!
Do I need some extra code in the controller to change the date format back into its original form? Is this a bug in the localization code of cakephp or did I miss something? Note, that my controller just uses patchEntity to process the posted data.
I already tried adding date('invoice_date', 'dmy') in the validationDefault method of the table object, but this didn't change anything:
$validator
->date('invoice_date', 'dmy')
->requirePresence('invoice_date', 'create')
->notEmpty('invoice_date');
Thanks for your help!
I just found the solution to my problem: in bootstrap.php, I had to add:
Type::build('date')->useLocaleParser();
Type::build('datetime')->useLocaleParser();
With that, I can enter dates like 31.12.16 (d.m.y) and the date gets correctly saved in the database. This works with the simple validator:
$validator
->date('invoice_date')
->notEmpty('invoice_date');
To also support dates like 31.12.2016 (d.m.Y), I had to add an extra parameter to the date validator, like this:
$validator
->date('invoice_date', 'dmy')
->notEmpty('invoice_date');

reformat date that is pulled from database table

I have a website which uses smarty templates.
I have a table in my db called posts that has various columns, one being "date_added". I managed to have that displayed on the posts by editing one of the Smarty templates for "posts" however, the date format is YYYY-MM-DD.
Is there any easy way for me to change this? Perhaps with jQuery?
Ideally, I want to only show the abbreviated month, with the day positioned next it. This is for a blog style post, but this isn't WordPress.
Right now the smartytemplate the shows the date_added reads like this:
{$posts[i].date_added|stripslashes|nl2br}
Where posts is the table and date_added is a column in that table.
An exact example can be seen here in the top right corner of each post.
http://www.elegantthemes.com/preview/LightBright/
Does anyone have a good suggestion of how I can achieve the desired request?
If you are looking for a javascript solution, you can take a look at the incredible JS Library MomentJS. It is very lightweight and does numerous date and time formats.
http://momentjs.com/
Just include the minified script file in your HTML .
For your exact case, you would use momentJS as such:
First create the momentJS date object:
var moment_date = moment(date_from_database, "YYYY-MM-DD");
Then to display the date as you want:
var date_string = moment_date.format("MMM DD"); // ex. = "Mar 03"
More documentation here: http://momentjs.com/docs/#/displaying/
Then you can use your DOM manipulation library (JQuery for example) to place that string somewhere in your HTML
Good luck
- K

Ext JS 4 - how to add a time stamp to a text area form field?

I have an form with a text area field. I want to add some text (a date/time stamp) when the user clicks in to the form. I am assuming I need to catch a click type event when the user clicks in to the field and then edit the field value and insert the text I want. Is this the best approach?
Looking for suggestions based on using Ext JS 4 / MVC.
As mentioned by you - "I need to catch a click type event when the user clicks in to the field" - One way to achieve this and appending of timestamp to the value could be by using the focus event in following manner:
focus:function(){
var value = this.getValue();
value += new Date().getTime();
this.setValue(value);
}
Just that the date used here is the client's system date.
Hope this helps.

Dynamic JQuery date picker code

I need to create dynamic filter that adds/removes rows dynamically.
It contains a drop-down box. Depending upon the drop-down box value selected, I create a dynamic <TD> that may have a text field or drop-down list.
If it's a text field, then I have to add date picker for that text field.
I have done this, except date picker for dynamically generated text field.
If you're creating 100 rows, the text fields' names should be same for all rows.
How to add datepicker for dynamically generated text field?
I had the same issue.
You would need to rebind the DatePicker to the dynamically added row.
The date picker associates a hadDatePicker Class to the dynamic row.
So you would need to remove that and rebind.
Something like this -
jQuery('.date-pick').removeClass('hasDatepicker').datepicker({
dateFormat: 'mm-dd-yy'
});
Regards,
Tina Agrawal
Actually i did use the solution provided by #Tina Agrawal But since now, when i select a date from the calendar, i click again and re-select. If i click on next month, it will go to 1900-01-01.
Well it was so strange...
After two hours of trial and errors and research.
i simply did:
$('.date-pick').live('click', function(){
$('.date-pick').datepicker();
});
Well it works.
I had the same issue and solved it in a different way. Although I am not very sure why is it working as I am very new to jquery. I wrote the following and it iterates the entire set of controls having the class "class_date" and rebinds the datepicker control to it.
$(".class_date").removeClass('hasDatepicker').datepicker();
Tirst add a class attribute as "date" to your input or div.
After dynamically add a text input to have to recall $('.date').datePicker() again to bind datePicker to new inputs or div.
I had a similar problem in that when dynamically adding new rows to my table the Date Picker fields in the new rows (any row added to the DOM dynamically) were all updating my initial rows Date Picker fields.
Removing the hasDatepicker class as suggested above was not enough to solve my issue, probably as I was using .clone() to create my dynamically added rows.
The solution when cloning rows was to remove the cloned input fields, re-create them, add them to my newly cloned table row and THEN re-initiate the Date Picker
For example:
//Remove exisiting cloned input fields
new_row.find("td.date input").remove();
//Create new input fields and append to table td
var date_tds = new_row.find("td.date");
$('<input />', {"name":"gStartDates["+n_array_pos+"]","type":"text"}).appendTo(date_tds[0]);
$('<input />', {"name":"gEndDates["+n_array_pos+"]","type":"text"}).appendTo(date_tds[1]);
//Re-initiate datepicker on the input fields
new_row.find("td.date input").datepicker({
dateFormat:"dd-mm-yy",
minDate:StartDate,
maxDate:EndDate
});
Use JQuery Live to access the dynamically created DOM.
http://api.jquery.com/live/
The you can attached the picker.
http://jqueryui.com/demos/datepicker/
one should use ".on" instead of live - see
http://api.jquery.com/on/