Convert data in TYPO3 fluid form - typo3

I need yours help. I have follow form:
{namespace femanager=In2code\Femanager\ViewHelpers}
<div class="femanager_fieldset femanager_membershipend control-group">
<label for="femanager_field_membershipend" class="control-label">
<f:translate key="tx_feusersplus_domain_model_user.membershipend" default="Expiration date of the membership"/>
</label>
<div class="controls">
<femanager:form.textfield
disabled="true"
id="femanager_field_membershipend"
property="membershipend"
class="input-block-level"
additionalAttributes="{femanager:Validation.FormValidationData(settings:settings,fieldName:'membershipend')}"
/>
</div>
</div>
And it get date in the next format - 1493942400. How I can make good look for date ? Thank you for advice!

Your property seems to be declared as integer (unix timestamp) in the model.
You can change the field to the following:
<femanager:form.textfield
disabled="true"
id="femanager_field_membershipend"
property="membershipend"
class="input-block-level" value="{yourModel.membershipend-> f:format.date(format: 'd.m.Y')}"
additionalAttributes="{femanager:Validation.FormValidationData(settings:settings,fieldName:'membershipend')}"
/>
This will format the property to a readable Date. But after that you will get problems saving the property correctly. If the property is really an integer, you need to write a converter for converting the date to an unix timestamp. It must work like here just in the reverse and I think TYPO3 does not have the correct converter for your needs out of the box.
I recommend you to change your property to DateTime (including the database field). Then you can use the DateTimeConverter of TYPO3 to save the data correctly.
EDIT: In your case the field is disabled="true" which should mean that the data will not become submitted. In that case you should not get problems with converting after submitting the form.

Related

ASP.Net Core MVC date input value

I created a edit view for a EF Model and have a problem with the datepicker.
Whenever i try to edit a `dataset, the edit view don't show me the old date values.
This is my Edit.cshtml Code:
<div class="form-group">
<label asp-for="BestellungsDatum" class="control-label"></label>
<input asp-for="BestellungsDatum" type="date" class="form- control" value="#Model.BestellungsDatum" />
<span asp-validation-for="BestellungsDatum" class="text-danger"></span>
</div>
This is what it looks like, but there have to be the old value at this position:
When i change the input to type="text", the value is shown but there is no datepicker.. Any solutions on this?
type="date" generates the browsers HTML-5 datepicker if supported. The specifications require that the value be formatted in ISO format (yyyy-MM-dd) which is then displayed in accordance with the browsers culture.
Add the asp-format to format the value, and remove the value attribute (Tag Helpers correctly generate the value attribute for correct 2-way model binding and you should never attempt to add it yourself)
<input asp-for="BestellungsDatum" type="date" asp-format="{0:yyyy-MM-dd}" class="form-control" />
Note the HTML-5 datepicker is not supported in IE, and only in recent versions of FireFox. If you want a consistent UI, then consider using a jQuery datepicker instead.
Just like to add an addition to the accepted answer:
<input asp-for="BestellungsDatum" type="date" class="form-control" />
Rather than adding asp-format to the view, add DataFormatString to the data Model or ViewModel, so you don't have to add it to every view that uses it:
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime BestellungsDatum { get; set; }

Bootstrap Form Helpers country picker doesn't get serialized

I have a country picker in my form like this:
<select class="bfh-countries text-left" name="country" id="country" data-country="DE">
</select>
I can get the value with jQuery like this:
$("#country").val()
but when i try to serialize the form with $("#myform").serializeArray() The value for "country" is an empty string.
How can i fix this?
I ran into this problem and it took me forever to find because there aren't any examples of it. What you really want to do is use data-name="country", which names the hidden variable on the back end as country. For the country picker, you can use the div tag as follows:
<div class="country bfh-selectbox bfh-countries" data-flags="true" data-filter="true" data-name="country" data-country="POSTBACK_VARIABLE_GOES_HERE"></div>
If you do this, you'll find a hidden variable that's added to the page as follows:
<input type="hidden" name="country" value="US">
The value above assumes you selected United States but it is entered as a 2 character code, which could then be entered as data-country above if you need to do server-side validation and display the page again without forcing the user to select the value all over again.
This was seriously a nightmare to find.

Bootstrap 3 input Date format

I would like to know without using any plugin/library, is it possible to format bootstrap date input format.
My webservice will return ISO.DATE pattern = "yyyy-MM-dd", and bootstrap displays it in MM/DD/YYYY format. I want to change it to DD/MM/YYYY format.
Is it possible to do ? I googled and every one seem to be using some library. Since my requirement is simple, I do not want to use any library. Or do you think a library is required.
Any help is appreciated.
<div class="form-group">
<label for=displayFrom class="col-md-3 control-label"> Date </label>
<div class="col-md-4">
<form:input type="date" class="form-control" path="displayFrom" id="displayFrom"
placeholder="display From"/>
</div>
<div class="col-md-5 iserror">
<form:errors path="displayFrom"></form:errors>
</div>
</div>
You are using HTML5's date input which uses the YYYY-MM-DD format, which is unchangeable right now. Chrome and Opera uses the local computer's locale to set the format of the input, Firefox and IE uses the default YYYY-MM-DD.

laravel: when submitting form encoded in UTF-8 it is converted to java data type

I am using laravel 4.2. Im learning laravel and find myself caught up in one problem and I have tried in many forums and I haven't found the answer anyware.
My problem is as follows:
I have this form embeded in a php view file:
{{Form::open(['route'=> 'home.store'])}}
<div class="container col-xs-5 ">
<form class="form-horizontal">
<div class="form-group col-xs-8">
<!-- Split button -->
<div class="btn-group">
<select name="country" class="btn btn-success dropdown-toggle" >
<option disabled selected>Escoger País</option>
<option>Argentina</option>
<option>Bolivia</option>
<option>Chile</option>
<option>Colombia</option>
<option>Costa Rica</option>
<option>Cuba</option>
<option>Ecuador</option>
<option>El Salvador</option>
<option>Guatemala</option>
<option>Honduras</option>
<option>México</option>
<option>Nicaragua</option>
<option>Panamá</option>
<option>Paraguay</option>
<option>Perú</option>
<option>Puerto Rico</option>
<option>Uruguay</option>
<option>Puerto Rico</option>
<option>República Dominicana</option>
<option>Venezuela</option>
</select>
</div>
</div>
</div>
{{Form::close()}}
Now, in home.store I have:
$user-> country = Input::get('country');
This is meant to be stored in a database table with a field named "country" that is of type ENUM with the same options as the form. It works perfectly when I pick options without ansi character codes. However when I choose the option that contains a spanish tilde (´),that is set in ansi code, they cannot get stored in the database.
Now, to check what is getting as input I used in home.store :
return Input::all();
And it ouputs:
{"_token":"ofyHW7ElogegKJwMXQL3HsbugCSnRxbtkm0GVQ8y","country":"Per\u00fa"}
I can recognize the problem as: acsii code &#250 is translated to java \u00fa.
I have checked everywhere in the framework (FormBuilder.php and HtmlBuilder.php)to see if something is being defined as java in laravel but everything is set to UTF-8, so as the database, and so as the meta tag in the html view (the browser is set to utf-8 too)
I would greatly appreciate anyone help on this.
Thank you so much.

Date Select Error in Ektron

I have a form that is using the calendar/date selection tool within Ektron, but when users select the current date (or any date, for that matter), it gives an error saying that you need to select a date in the past.
We haven't tooled around in the code for this form, but it almost sounds like a validation issue.
Here's the code, as is, from Ektron.
<p align="center" style="text-align: left;">Date program was presented: 
<ektdesignns_calendar title="Date presented" id="Date_presented" onblur="design_validate_xpath('number(translate(.,\'-\',\'\')) <= number(translate($currentDate,\'-\',\'\'))',this,'Date in the past (required)');" ektdesignns_name="Date_presented" ektdesignns_caption="Date presented" ektdesignns_invalidmsg="Date in the past (required)" ektdesignns_validate="xpath:number(translate(.,'-','')) <= number(translate($currentDate,'-',''))" ektdesignns_basetype="calendar" ektdesignns_datatype="date" ektdesignns_validation="datePast-req" name="Date_presented">
<input type="text" size="30" readonly="readonly" unselectable="on" />
<img width="16" height="16" class="design_fieldbutton" alt="Select date" src="[skinpath]btncalendar.gif" unselectable="on" /></ektdesignns_calendar></p>
My knowledge on validation is limited, but it looks like it's parsing the date as an integer. Is it possible to add a day (+1) to the current date so that it interprets any day as valid as long as it's not in the future?
I guess this is a HTML form as opposed to a Smart form?
If so, have you checked the validation settings on the calendar field? If you edit the form, right-click on the field and choose Field Properties you will get the properties window. Go to the Validation tab and check the setting in the Validation drop down.
There are options for ensuring the date is in the past or the future. Perhaps one of these options has been set?