I have in my symfony5 form input
->add('required_amount', IntegerType::class, [
'label' => 'Požadovaná částka',
'grouping' => true,
]);
when run form the thousand sepator isn dispaly on typing number
whatis wrong in my code, may I use number format in input in form in symfony
I copy your code and runs just fine to my 4.4.4 symfony project. If you submit this form the output will be 1,000,000 or 1.000.000 depending on your locale value default set in .env file. The grouping property is in IntegerType , MoneyType and NumberType and do the same in all this classes , so this is not your problem. If you describe something in client side (as you type the numbers to add the separator) you need to go with javascript not php, but i don't thinks this is the case.
Related
I have created a custom field in woocommerce where i want shopowners choose a year of publishing (books in this case).
So far i have:
//Custom Product Date Field
woocommerce_wp_text_input(
array(
'id' => '_custom_product_date_field',
'placeholder' => 'Publicatiedatum',
'label' => __('Publicatiedatum:', 'woocommerce'),
'type' => 'date',
'date-type' => 'years'
)
);
How can i set the date-type to years, as the last key => value (date-type:years) is not working?
I was curious since I was looking for details on using the date field in a woocommerce custom field. I didn't need year only specifically but it was an interesting rabbit hole to run down.
Trying to understand a bit more how woocommerce_wp_text_input creates these fields it started to become more apparent that supplying the type attribute simply passes it on to the HTML attributes. That said, these are standard HTML elements, not a wrapper of sorts that produces more fancy fields utilizing things like jQuery which seems like what the OP was expecting.
Looking over the specs for the date-related HTML text input fields it becomes apparent that there is not an <input> of type="year" available in the spec. We are limited to the type's specified in the specs.
I was able to successfully create a month input with the following:
woocommerce_wp_text_input(
[
'id' => '_my_month',
'label' => __('My month', 'woocommerce'),
'value' => get_post_meta($post->ID, '_my_month', true),
'type' => 'month',
'custom_attributes' => [
'min' => '2020-01',
],
]
);
So understandably, from what I can see, doing what you are asking isn't possible unless the HTML specifications add a year input or woocommerce provides a bandaid when specifying type as year. Hopefully this better explains how woocommerce_wp_text_input expects the data to be formatted and what is really supported.
As an aside that might assist in completing the requirements of the original question through alternate means, you could attempt to implement a jQuery UI picker which supports year only. I however feel that the jQuery UI picker using year only is a bit clumsy being it provides a popup to simply choose a date from a dropdown AND the left/right pagination of the popup still pages through months while showing only years. You might as well just use a dropdown or a number field with the date min/max values you require, both have example code that can be seen in other answers on that aforementioned answer I linked.
I have the following input date on form:
echo $this->Form->input('fecha_limite', ['label' => __('Fecha límite'), 'type' => 'date', 'class' => 'form-control']);
By default the months are shown on english locale and I want to establish spanish locale.
I have tried to change it using intl.default_locale since config/bootstrap.php and using I18n::locale() and doesn't works...
Any ideas?
this problem probably has some Reason.cakephp 3 has cache for i18n therefore you must delete cache .maybe you was a mistake in file locale.you have to don't use of two line in that file.
However maybe because of use form helper.please test outside form helper
I am using the 'repeated' field to validate a password in the form.
According to the documentation, the 'repeated' field group is supposed
to, render two identical fields (which it is doing) and submit only if
the values from both the fields match or it should throw a validation error. The
second part somehow does not seem to work. I tried using the example
code as is but, the form submits with no issue or error even if the
passwords do not match. Did anyone else come across the same issue or
is there something I am doing wrong?
I did not add a validation file nor do I use annotations. From what I understand from the documentation, the repeated filed checks the values from first_name and second_name fields automatically and submits the form only when both the values are equal which it is not doing. This is the code I am using,
->add('password', 'repeated',
array(
'type' => 'password',
)
)
This renders two fields 'First' and 'Second' and passes an array with the 'First' and 'Second' values on submit.
the correct syntax would be
->add('tmpPassword', 'repeated', array('type' => 'password'));
if you use the the same key for the field as for the type it can not assign the value correct.
It turns out it was a stupid mistake on my part. I was not validating the form in the controller. Once, I do that it works fine.
I have a simple ZF form that includes a hash element:
$hash = new Zend_Form_Element_Hash('hash');
$hash->setSalt('hf823hflw03j');
$hash->addErrorMessage('Form must not be resubmitted');
This works ok, but if I choose to strip out all the decorators and format the form using :
$this->setDecorators( array( array('ViewScript', array('viewScript' => '_form_register.phtml'))));
Then it seems that the hash value is renewed each time it is submitted and thus doesn't work.
In addition, PHPunit thinks the form element hash is invalid and so doesn't test the form processing.
Is there any solution to this?
Do you really need to use viewScript Decorator? Otherwise try to use this:
$this->setDecorators(array('ViewHelper','Errors'));
If you want to change the look of the Errors, you could create your own ErrorDecorator and then use it as follows:
$this->setDecorators(array('ViewHelper', new My_ErrorDecorator()));
I have a form in Zend_Form that needs some checkboxes and I'd like them to be regular old checkboxes. You know, you give em a name and a value. If they are checked your post data contains name=>value.
Zend_Form is generating two inputs fields. One, the checkbox with a value=1 and the second a hidden input with a value=2. Both have the same name. I understand in theory how Zend expects the checkbox to work, but that's not how I expect it to work and it's not how I want it to work. How do I get my old fashion HTML checkbox back?
I have tried using $this->createElement, $this->addElement and creating a Zend_Form_Element_Checkbox manually. None allow me to set the checkbox's value and all generate the hidden input.
The final and REALLY correct answer is to add an option to the element :
$this->addElement('checkbox', 'my_element', array(
'label' => 'My Element Label',
'name' => 'my_element_name',
'disableHidden' => true
));
Zend_Form_Element_MultiCheckbox is what you're looking for.
The standard Checkbox element is meant to represent "yes/no" scenarios.
You could extend Zend library and add your own custom form element to render it just like you expect it. I did it for having a date field and it worked just fine.
I wonder why that does not work for you. You can set the values to anything you want (setCheckedValue() and setUncheckedValue()). So the only difference to normal checkbox is
if (null == $this->_getParam('checkbox', null)) {
//vs.
if ($unchecked == $this->_getParam('checkbox')) {
What exactly are you trying to do?