How to use f:translate within additionalAttributes of f:form.textfield - typo3

I'm trying to insert a translated placeholder within my f:form.textfield
<f:form.textfield name="search[sword]" value="{sword}" class="form-element" additionalAttributes="{placeholder: '<f:translate key="placeholder" />'}"/>
The output works if I replace the placeholder with normal text. I can output my translated placeholder elsewhere as well, but not within the attribut of the f:form.textfield.
I can not spot a syntax error.

Use inline sysntax, for additional attributes like:
<f:form.textfield name="search[sword]" value="{sword}" class="form-element" additionalAttributes="{placeholder: '{f:translate(key:\'placeholder\')}'}"/>
With TYPO3 CMS >= 6.2 you can use placeholder directly as argument for textfields:
<f:form.textfield name="search[sword]" value="{sword}" class="form-element" placeholder="{f:translate(key:'placeholder')}"/>

Related

TYPO3 Femanager Passwort additionalAttributes

I want to extend the additionalAttributes with a second Attribute. In the original Partials it looks like this:
<f:form.password
id="femanager_field_password_repeat"
name="password_repeat"
class="input-block-level"
value=""
additionalAttributes="{femanager:Validation.FormValidationData(settings:settings,fieldName:'password_repeat')}" />
I try this:
additionalAttributes="{femanager:Validation.FormValidationData(settings:settings,fieldName:'password'),placeholder: '{password_repeat}'}" />
With several Verions of Escaping the femanager:Validation..... Got this Error:
The argument "additionalAttributes" was registered with type "array",
but is of type "string" in view helper
"TYPO3\CMS\Fluid\ViewHelpers\Form\PasswordViewHelper“
Any Ideas?
I think
Validation.FormValidationData()
is a viewhelper that returns a whole array which is expected for the attribute "additionalAttributes".
Because of that it's difficult to extend the array at this place.
But as far as I know the femanager-viewhelper itself offers the possibility to extend the final array, all to do is to give your array as a further argument which is called 'additionalAttributes' as well.
A short example:
<f:form.password
property="password"
additionalAttributes="{
femanager:Validation.FormValidationData(settings:settings,
fieldName:'password',
additionalAttributes:'{required:\'required\',pattern:\'.{8,}\'}')}"
}" />
Notice the array of 2 values (required and pattern).
I also recommend to have a look at the viewhelper on github:
https://github.com/TYPO3-extensions/femanager/blob/master/Classes/ViewHelpers/Validation/FormValidationDataViewHelper.php

How to disable automated encoding of special characters in fluid partials (TYPO3)

Should be simple enough. I'm trying to add an input field to a fluid partial in the extension "yag" (yet another gallery).
Input: <f:form.textfield id="live-filter" name="test" />
Output: <input id="live-filter" type="text" name="test" />
Somehow the code get's filtered along the way, but I don't know why.
TYPO3 v. 6.2
YAG v. 3.2.1
Edit: A wild guess would be some output filtering in TYPO3 itself, but where? I didn't set anything by purpose.
You need to traverse the path upwards to check if there is any fluid tag wrapped around it, that does escaping. In general, all tags do escaping.
Also check the code around <f:render partial....
It could also be that the TypoScript code that does calls the fluid template, has a .htmlspecialchars = 1 set.
Since TYPO3 8 there is another pitfall: Custom Viewhelpers do htmlspecialchars on the output unless told otherwise. The solution is:
<?php
namespace Vendor\ArTest\ViewHelpers;
class YourViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper{
/**
* As this ViewHelper renders HTML, the output must not be escaped.
*
* #var bool
*/
protected $escapeOutput = false;
As of TYPO3 ver. 9.5 and up to ver. 10.4 you could also wrap the output in the Fluid template into <f:format.htmlentitiesDecode> Tags like this:
<f:format.htmlentitiesDecode>
<f:form.textfield id="live-filter" name="test" />
</f:format.htmlentitiesDecode>
Further information on this can be found in the TYPO3 View Helper Reference.

FLUID ViewHelper form in new window

I would like to add the target attribute to a FLUID form, so that after submitting the form, a new window is created.
This does not work, and produces an error:
<f:form target="_blank" action="..." name="..." id="..." pageUid="..." controller="..."></f:form>
Any ideas on how to make the to open in a new window?
I use TYPO3 6.2beta5
As the f:form ViewHelper inherits from the AbstractTagBasedViewHelper, it shares the same allowed attributes.
The fluid documentation inside the TYPO3 Flow documentation shows you all allowed attributes.
To answer your question, the correct way to use it would be:
<f:form additionalAttributes="{target:'_blank'}">FORMCONTENT</f:form>
Note that the additionalAttributes argument is an array. If you were to add more than 1 custom attribute, you would do it like that:
<f:form additionalAttributes="{target:'_blank', data-validate: 'foo'}">FORMCONTENT</f:form>
EDIT
The AbstractTagBasedViewHelper changed, so the answer as of today for TYPO3 CMS v7 would be: There's an attribute data for that which takes an array of keys and values.
<f:form data="{foo: 'bar', validate: 'baz'}" ....>
FORMCONTENT
</f:form>

HTML5 multi="true" tag doesn't work

i use Eclipse kepler
in dynamic web project
i create html(HTML5) file and use code for Multi select file upload system
<input type="file" multiple="true" />
but can't select multiple with ctrl+click
and my eclipse has warning
Multiple annotations found at this line :
-Undefined attribute value(true)
-Undefined attribute value(true)
any suggestion?
You need to use the attribute's name as its value:
If the attribute is present, its value must either be the empty string
or a value that is an ASCII case-insensitive match for the attribute's
canonical name, with no leading or trailing whitespace.
(http://www.w3.org/TR/html5/infrastructure.html#boolean-attributes)
In other words, just use:
<input type="file" multiple>
or
<input type="file" multiple="multiple">
If it does not work, then the reason is that you are using a browser that does not support the multiple attribute, such as IE 9. To deal with such browsers, you can add some JavaScript that tests whether the input element has the multiple property and if it does not, creates some additional file input elements (possibly in a loop that lets the user specify any number of files).
The warning should really be an error message, since true is not a valid value for the multiple attribute. As #IlmoEuro explains, the value should be empty or multiple. However, the value has in practice no impact; browsers recognize just the attribute name and ignore the value (even if you write multiple="false" for example).

Using negative value in Zend Form Element Radio causing html errors

$score = new Zend_Form_Element_Radio('score');
$score->setRequired(true)
->setSeparator('')
->setMultiOptions(array(1 =>'Positive', -1 =>'Negative'))
->setDecorators(array('ViewHelper'));
Renders as
<label for="score-1">
<input name="score" id="score-1" value="1" checked="checked" type="radio">Positive
</label>
<label for="score-1">
<input name="score" id="score-1" value="-1" type="radio">Negative
</label>
Is the fact that it's using the same ID for the inputs and labels normal behavior or a bug?
How can I correct this?
I can't change the values as technically they are required to be that way
The real problem this causes is that when you click the negative the positive gets selected instead!
Thanks
Looks like the standard ViewHelper decorator for a radio control uses a FormRadio view-helper. When this view helper creates the id it uses on the <input> element and the <label> element, it first applies the standard AlNum filter, which is filtering out your minus sign.
So, it looks to me that instead of using the standard ViewRenderer decorator, you will have to create a custom decorator that calls your own custom FormRadio view helper.
You might be able to avoid creating your own decorators and view helpers by creating your own custom AlNum filter that allows those minus signs. The trick is to set that path only for this single use so that you;ll be able to use the normal Alnum filter for other elements.
Alternatively, you could probably trick the ViewHelper into using a custom FormRadio helper by adding a helper path on the view object so that it loads your custom view helper instead of the standard one.
Just some ideas.