how to make an input box and datetime picker a read only in cakephp 3.5? I've tried to use the readonly and editable but it doesn't work.
use readonly attribute like below -
echo $this->Form->input("name",array('readonly' => 'readonly'));
Related
I'm trying to put the disabled attribute in in angularJS It doesn't work at all, I've already tried ng-disabled="true", via script and it doesn't work. If I change it to it works normal, but I need to do it with the . Does anyone know how to do it?
Lets say you have a textarea like this
<textarea type="text" ng-model="someModel" ng-readonly="disablingAttribute"></textarea>
And inside your controller if you have
$scope.disablingAttribute = true;
It will functionally disable your textarea.
For more information on this, read about ng-readonly directive
I'm trying to create input limitted to only 4 characters using reactjs semantic ui, I have tried a lot of ways of doing that but none of them seems to work.
<Input fluid
value={this.state.code}
type="text"
minlength="4" maxlength="8" size="10"
placeholder={t('Code')}
onChange={this.onCodeChange.bind(this)}
error={this.state.formErrorsKeys.code}
/>
Also I'm thinking if it's possible to make an input splitted into 4 input areas.
Cheers!
All you need is to add custom validation function which takes the input value and returns modified string.
Something like this:
const validateField = string => {
return string.slice(0, 4);
};
console.log(validateField('string')); // => 'stri'
console.log(validateField('test_test')); // => 'test'
Here is an example: https://codesandbox.io/s/r55228449p
UPD
Also I'm thinking if it's possible to make an input splitted into 4
input areas
Updated the example to add something similar to "an input splitted into 4 input areas"
React Semantic UI expects camel case maxLength and minLength props which will be passed to the html input. You are using all lowercase. Changing the prop names should fix your issue, however as others have said, a custom validator function may be appropriate.
hi I would like to know how to place a attribute "value","defaultValue" or "placeholder" from form:input
Original Code
<form:input path="ggpath" cssStyle="width:100%"/>
What I want
<form:input path="ggpath" cssStyle="width:100%" value="example"/>
but if I place value attribute. It does give me an error. Any help would be greatly appreciated
Use following code
<form:input path="ggpath" style="width:100%" placeholder="example"/>
One way to do this is to keep that default value in command object like
private string ggpath="example";
This will be displayed as default value in the form. From spring 3.0 you can use placeholder tag also directly
I am using angucomplete-alt in many places of my web application (in forms), but i cant make the autocomplete fields as a 'required' field, even thought i've used the 'field-required' attribute.
angucomplete-alt#sectorSuggested(field-required= true,placeholder='Search sectors', local-data='sectors', selected-object='onSectorSelected', search-fields='Sector', pause='300', minlength='1', title-field='Sector',input-class="form-control form-control-small", name='sector')
how do i make it required field, please help :)
Going off of the documentation and examples I can see here, it looks like the attribute should be
field-required="true"
In the above example, his element looks like this:
<div angucomplete-alt="" id="ex8" placeholder="Search countries" pause="100" selected-object="countrySelected8" local-data="countries" search-fields="name" title-field="name" minlength="1" input-class="form-control form-control-small" match-class="highlight" field-required="true" class="ng-isolate-scope">
Additionally, if you have many required fields, his documentation states:
Set custom class name for required. Unique class names need to be set
when you have multiple directives to validate
You can do this, using the field-required-class attribute.
Taken from here
you can use field-required = "true"
and it should work fine.
I'm adding an input field via Razor
#Html.TextBoxFor(x => x.ccVersandkosten, new { #class = "form-control" })
but it adds some html attributes that I don't want:
<input class="form-control" data-val="true" data-val-number="Das Feld"Versandkosten" muss eine Zahl sein." data-val-required="Das Feld "Versandkosten" ist erforderlich." id="ccVersandkosten" name="ccVersandkosten" type="text" value="0" />
The attribute which I don't need is value="0". I thinks Razor adds the value attribute because my variable ccVersandkosten is a float, I could change this but it needs to be a float.
Is there a way to remove this attribute or keep Razor from adding it ?
in your model you define it float. "Float" must not be null. When model initialize, then not-nullable variables initialize by 0. This is not a razor feature, this is c# feature.
So razor display this field as 0. You can define variable as nullable (float? ccVersandkosten) to display nothing for value attr.
#model MyModel means var model = new MyModel();, so when you create a new class, c# initialize the not-nullable variables. (float, int, double, datetime,..)
Razor automatically sets the Value based on the property you are creating the textbox for (in this case x.ccVersandkosten). This is good.
If you want the initial value to be null, you must make ccVersandkosten nullable.
Razor will add this attribute regardless of the type of your ccVersandkosten property. The TextBoxFor helper creates an input element and, since inputs are usually meant for collecting data and sending it to the server, it must have a value.
If you don't need a value for your property, you're probably not using the correct helper. You have several options here: render your property using HiddenFor or, if you just want to display something, create a standard HTML label.
Judging from the generated validation code, your property may be decorated with the [Required] attribute. I only say "may", because all value type properties are automatically required. If you specifically set the [Required] attribute, then your inputmust have a value attribute which will get posted to the server and validated by the framework.