Input Lines of Data in Page Template Form - plone

I have a CMF Action to edit custom archetype type metadata, where author is one of the fields to be edited. The following code in editing form template is for StringFiled:
<input type="text"
name="new_author:list"
value="author"
size="40"
tal:condition="canModifyItem"
tal:attributes="value obj/getAuthor;
id string:${item}_author;" />
If I change the field from 'author' to 'authors', using LinesField instead of StringField, how can I update the template for input multiple lines of data (one name per line)?

you have to use a textarea, instead of input tag, and parse the input data through a split('/n') in order to get a list of inputed lines.
also,
instead of tal:attributes="value... you have to use tal:content="obj/getAuthor"
hth

Related

Select2 multiple select passing key,value pairs on postback

I am using Select2 Tags using a dropdown as well as a direct input and have the following code in my View:
<select id="lessonTags" class="form-control" multiple="multiple" style="width:100%" name="SelectedTags">
#foreach (var lesson in Model.Lessons)
{
<option value="#lesson.Id">#lesson.Title</option>
}
In my viewmodel I just created a temp variable string[] SelectedTags which gives me the string of what was selected via the dropdown as well as anything that was typed in that was not in my original options.
So currently I have to loop through my data and match to see if the SelectedTags array has a match on my db, if it does then I can use that Id in my model, if it doesn't exist then I have to Create that lesson in my DB.
I find this to be extra processing, it would be nice if I can just pass say a key, value pair of ID/Lesson.Title and anything that I typed wouldn't have an ID so I can easily identify what needs to be created on the DB.
Is there a way to pass the key/value pair via the name tag?
EDIT: Currently whats getting returned is the lesson.Id if its in the list or the actual text if its not - the issue with this is if the user types in a number, i can't discern between an Id and the users number...hence I am thinking I need to somehow flag a new piece of data.

Symfony2 - Array of data

This is the last problem I am facing with Symfony2. So, I am using a normal form, not the form builder.
I have one table called alert which has the standard fields. I have a second table called booking_class which has an alert key in it which is linked to the alert table. Its a one to many relationship. In my form, I have something like
<input type="text" name="na_booking_class[]">
<input type="text" name="na_booking_class[]">
So this input is placed into an array. Now in my controller, I presume that this will give me my array of data
$alert->setBookingClass($request->get('na_booking_class'));
However, setBookingClass only accepts a String. So I need to somehow loop this array and pass the String values to setBookingClass.
How would this be achieved?
Thanks
If you get an array from this $request->get('na_booking_class'); then you can use:
$arrBooking = $request->get('na_booking_class');
foreach($arrBooking as $booking) {
$alert->setBookingClass($booking);
}
Try with this.

Multiple Field types of fields in Symfony2 Datatimepicker & filter

I'm trying to work with the bundles :
https://github.com/lexik/LexikFormFilterBundle
https://github.com/stephanecollot/DatetimepickerBundle
So I've a filed of my form with to apply a filter acordin to this field
->add('fecha', 'filter_date_range');
Now I wanna add another parameter because this field is a data then I wanna see a datapicker so I need to apply another parameter here like
->add('fecha', 'filter_date_range collot_datetime');
But this not works so, are there some way to implements the both bundles in a field?
This can not be done out of the box - field can have only one type.
If you need to customize form field type you can create your own: http://symfony.com/doc/current/cookbook/form/create_custom_field_type.html (based on these two)

getting textfield output partly unvisible

In a Drupal content type a need to get the output of a field partly unvisible. These are bank account details, the IBAN.
Normally the field shows 1234567. I need to get xxxx567. I need to show only the last 3 numbers/letters.
Also I need this output in field edit form.
On the display end you could change the output using a simple PHP function in the theme template by grabbing a substring of the field's last three digits and concatenating it with "xxxx" before printing.
You might also consider doing this at the formatter level by using the 'custom formatter' module perhaps?
https://drupal.org/project/custom_formatters
To do this on the edit screen is trickier. I suppose you could do a hook form alter to use PHP to change the field value, but I am afraid you will rewrite the field value when you save the node with the 'xxxx' instead of the real data.
I wonder if it would make sense to 1.) hide the actual field, 2.) create a dummy field that displays the text formatted as "xxxx567" to the user, and 3.) write some javascript that populates the hidden field with the visible field's value if it is changed. Presumably the form would still throw values if the hidden field did not meet formatting requirements.

Formatting th:field in Thymeleaf

I have a form input field in Thymeleaf. The field (bookingEntry.datefrom in the code snippet below) is type Date. I use a datepicker to allow the user to select and format the required date to enter the field. This is all fine.
However, I want the initial value of the date (which I have set to the current date) to be displayed in the format that I choose. So, how do I format the date initially shown in a th:field. th:value is ignored (Thymeleaf is getting the value from the backing object, as it should) and I can't seem to apply a format to the th:field.
Thymeleaf code is:
<input type="text" class="form-control getdate"
th:field="*{datefrom}" placeholder="Date From"
th:value="${#dates.format(bookingEntry.datefrom, 'dd-MMM-yyyy')}"/>
I'm sure that I could use a String which is initialise in any format that I choose, rather than a Date type, but I wondered if there was a way to format initial values in a th:field?
Many thanks
I missed the simple answer, simply because of my limited knowledge of Spring. I'm adding it here incase it helps any other novices like me.
The #DateTimeFormat annotation on the element in the object being passed to the form does the job. It ensures that the Date object is formatted in the way that you wish (irrespective of whether you are using Thymeleaf or not).
In the example above, within the bookingEntry object
#Temporal(DATE)
#DateTimeFormat (pattern="dd-MMM-YYYY")
private Date datefrom;
In case your date is null, it will give you error. We have to check the value before we parse the date.
<input type="text" name="date"
th:value="${user.dateOfBirth}?${#dates.format(user.dateOfBirth, 'dd-MM-yyyy')}:''"
placeholder="dd-mm-yyyy" id="pickyDate"/>

Resources