hello I was trying to make text box on the page read-only and I tried what exactly what I think is enough but the text box still writeable and I still confused and don't know what I missed there.
I tried to write
'readonly' => true,
'readonly' => 'true',
'readonly' => 'readonly',
and all didn't worked for me :(
function my_custom_checkout_field( $checkout ){
echo '<div id="EATM_custom_checkout_field">';
echo '<input class="EATM_checkout_exchange_rate" value="'.$this->exchange_data['EATM_exchange_rate'].'" hidden/>';
echo sprintf('<div class="EATM_container-payments"><div class="EATM_container-image-checkout"><img src="%1$s" /></div>',$this->payment_images[ str_replace(' ','_',$this->exchange_data['EATM_payment_send_from']) ] );
echo "<div class='payment'>";
woocommerce_form_field( 'my_field_name_1', array(
'type' => 'text',
'class' => array('my-field-class form-row-wide'),
'label' => __('ارسال'),
'required' =>true,
'readonly' =>true,
'value' =>$this->exchange_data['EATM_payment_send_from'],
'placeholder' => __('Send'),
), $this->exchange_data['EATM_payment_send_from']);
use the custom_attributes tag:
function my_custom_checkout_field( $checkout ){
// ...
woocommerce_form_field('my_field_name_1', array(
'type' => 'text',
'class' => array('my-field-class form-row-wide'),
'label' => __('ارسال'),
'required' => true,
'custom_attributes' => ['readonly' => true], // or ['disabled' => true]
'default' => $this->exchange_data['EATM_payment_send_from'],
'placeholder' => __('Send'),
), $this->exchange_data['EATM_payment_send_from']);
Also, I think the value field should be default or use the last parameter (like you are doing) and remove the value line entirely.
Documentation here: https://rudrastyh.com/woocommerce/woocommerce_form_field.html
To make a textbox readonly add
disabled
like this
<input type="text" value="1" class="form-control" disabled="">
Related
So I have an PHP file that includes a form so that users can post jobs on my website. I want to make some fields of this form ReadOnly to the user. How?
public static function init_fields() {
if ( self::$fields )
return;
self::$fields = apply_filters( 'submit_job_form_fields', array(
'job' => array(
'job_category' => array(
'label' => __( 'Job category', 'job_manager' ),
'type' => 'select',
'required' => true,
'options' => self::job_categories(),
'placeholder' => '',
'priority' => 3
),
'job_description' => array(
'label' => __( 'Description', 'job_manager' ),
'type' => 'text',
'required' => true,
'placeholder' => '',
'priority' => 4
),
I know this is probably easy to do, but for some reason I can't find how to do it.
Use the disabled attribute:
'job_description' => array(
'label' => __( 'Description', 'job_manager' ),
'type' => 'text',
'required' => true,
'placeholder' => '',
'priority' => 4,
'disabled' => 'true' //html disabled input
)
This is a proprietary config file. You need to look at the code that is parsing it and converting to HTML. It may allow passing through variables like readonly, or may not.
Try passing 'readonly' => true in your array.
Remember that someone can change the value of the readonly field using an inspector like Firebug, Chrome Developer Tools, etc.
I'd like to add event on text element
$barcodeFieldset = $form->addFieldset('form_barcode', array('legend' => Mage::helper('adminhtml')->__('Barcode Information')));
$barcodeFieldset->addField('barcode', 'submit', array(
'label' => Mage::helper('adminhtml')->__('Barcode'),
'name' => 'barcode',
'onKeyDown' => "alert('x')",
'required' => true,
'note' => 'If You want to scan barcode, focus to this textfield.',
$this->_isReadonly() => $this->_isReadonly(),
));
onKeyDown doesn't work. How to make it works?
For some reason Magento does not allow this. Here are the attributes that you can specify on a submit element: 'type', 'title', 'class', 'style', 'onclick', 'onchange', 'disabled', 'readonly', 'tabindex'. These come from Varien_Data_Form_Element_Abstract::getHtmlAttributes().
The only field type that allows onkeydown (written in lowercase) is the link field (Varien_Data_Form_Element_Link).
This is my idea.
$barcodeFieldset = $form->addFieldset('form_barcode', array('legend' => Mage::helper('adminhtml')->__('Barcode Information')));
$barcodeFieldset->addField('barcode', 'password', array(
'label' => Mage::helper('adminhtml')->__('Barcode'),
'name' => 'barcode',
'after_element_html' =>
"<script type='text/javascript'>" .
"$('barcode').setAttribute('onKeyDown', 'if(event.keyCode == 13){editForm.submit($(" . "edit_form" . ").action)};');"
. "</script>",
'required' => true,
'note' => 'If You want to scan barcode, focus to this textfield.',
$this->_isReadonly() => $this->_isReadonly(),
));
I am using the last version of cakephp, with the follow code I have to create a list of checkboxes.
echo $this->Form->input('regions', array(
'type' => 'select',
'hiddenField' => false,
'options' => $regions,
'multiple' => 'checkbox',
'div' => false
));
the code works 90%, I mean... the list has been created BUT I still see <div>
This is the result:
<div class="checkbox"><input type="checkbox" name="data[regions][]" value="1" id="Regions1" /><label for="Regions1">AAAA</label></div>
<div class="checkbox"><input type="checkbox" name="data[regions][]" value="2" id="Regions2" /><label for="Regions2">BBBB</label></div>
<div class="checkbox"><input type="checkbox" name="data[regions][]" value="3" id="Regions3" /><label for="Regions3">CCCC</label></div>
The result I need is:
<li>
<input type="checkbox" name="data[regions][]" value="1" id="Regions1" /><label for="Regions1">AAAA</label>
</li>
...
How can I do it ?
By setting 'div' => false, your prevents creating a <div> around the whole input section (i.e. the set of checkboxes). But obviously you want to disable the div's around the option. Unfortunately, I have not been able to find a way to disable this with Cake.
However, you can simulate the <li> items with some CSS trickery. Encapsulate the inputs in a div with a special class (the opposite of what you are doing now), then use CSS to force using <li> styling:
In your CSS:
.box2li div
{
display: list-item;
}
In your Cake view:
echo $this->Form->input('regions', array(
'type' => 'select',
'hiddenField' => false,
'options' => $regions,
'multiple' => 'checkbox',
'div' => array ('class' => 'box2li')
));
Each checkbox is now preceded by a... ...bullet
There should be a more simple way but you can always do it in the traditional way :)
while (list($key, $value) = each($regions)){
echo '<li>'.
$this->Form->input($value,
array(
'type' => 'checkbox',
'name' => 'data[regions][]',
'div' => false,
'value' => $key,
'label' => false,
'after' => $this->Form->label($value, $value)
))
.'</li>';
}
Not so beautiful, but works :)
Use Form->Checkbox instead of Form->input
$this->Form->checkbox('', array(
'label' => false,
'div' => false,
'class' => ''
));
$this->Form->checkbox('', array(
'label' => false,
'div' => false,
'class' => ''
));
$this->Form->checkbox('', array(
'label' => false,
'div' => false,
'class' => ''
));
I have an admin form field(textbox),
$fieldset->addField('ajax_time_interval', 'text', array(
'label' => Mage::helper('dealroom')->__('Page Refresh Time Interval'),
'class' => 'required-entry',
'required' => true,
'name' => 'ajax_time_interval',
));
I need to set a default value for this text field. I tried, setting 'value' => '120', in it. But its not working.
$fieldset->addField('ajax_time_interval', 'text', array(
'label' => Mage::helper('dealroom')->__('Page Refresh Time Interval'),
'class' => 'required-entry',
'required' => true,
'name' => 'ajax_time_interval',
'value' => '120',
));
How to set a defalt value in that field?
In my case, setValues() function was overriding the 'value' that I had set for the field.
Cause:
In my _prepareForm() function, I set the value as below:
$fieldset->addField('ajax_time_interval', 'text', array(
'label' => Mage::helper('dealroom')->__('Page Refresh Time Interval'),
'class' => 'required-entry',
'required' => true,
'name' => 'ajax_time_interval',
'value' => '120',
));
At the end of _prepareForm() function, there was the following line of code which would reset the form values:
$form->setValues($model->getData());
Solution:
Set model data before setValues() function as below:
if (!$model->getId()) {
$model->setData('ajax_time_interval', '120');
}
$form->setValues($model->getData());
you can do that by adding "default" attribute in field configurations.
$fieldset->addField('ajax_time_interval', 'text', array(
'label' => Mage::helper('dealroom')->__('Page Refresh Time Interval'),
'class' => 'required-entry',
'required' => true,
'name' => 'ajax_time_interval',
'default' => '120',
));
Remove the last semicolon....
Check this site help-me a lot:
http://www.excellencemagentoblog.com/magento-admin-form-field
Gl mf
I'm adding forms to my page using Zend/Form.
I'm adding elements by defining them as follows:
$this->add(array(
'name' => 'value',
'attributes' => array(
'type' => 'text',
'id' => 'value',
'autocomplete' => 'off',
'placeholder' => 'Cost',
),
'options' => array(
'label' => 'Cost',
),
));
As you can see there is a 'label' => 'cost' node, this generated a label to go with the input element.
How do I add classes, attributes to this label ?
Please try this, i haven't tested or used this, but going by the source it should function properly:
$this->add(array(
'name' => 'value',
'attributes' => array(),
'options' => array(
'label_attributes' => array(
'class' => 'mycss classes'
),
// more options
),
));
If this does not function, please leave me a comment. If it won't function, it is not possible using this approach, since the FormLabel restricts the validAttributes quite a bit:
protected $validTagAttributes = array(
'for' => true,
'form' => true,
);
This works well in Zend Framework 2.3 :
$this->add(array(
'name' => 'userName',
'attributes' => array(
'type' => 'text',
'class' => 'form-control',
'placeholder' =>'Username',
),
'options' => array(
'label' => 'Username',
'label_attributes' => array('class' => 'control-label')
),
));
$element->setOptions(array('label_class' => array('class' => 'control-label')));
Produces code like this:
<label class="control-label">
<input type="radio" name="option1" id="option1" value="1">
Option 1
</label>
<label class="control-label">
<input type="radio" name="option2" id="option2" value="2">
Option 2
</label>
I have tried this. It works in Zend Framework One.
Note if you use
$element->setOptions(array('label_attributes' => array('class' =>
'control-label')));
you get the undesirable effect for some reason of
<label attributes="control-label">
<input type="radio" name="option1" id="option1" value="1">
Option 1
</label>
For programmatic approach on ZF2+ try this:
$element->setOptions(array(
'label_attributes' => array(
'style' => 'color:gray;'
)
));
Inspired by Damon's answer.