Vuejs - setting the value of a textbox. (in laravel) - forms

I am trying to set the value of a textbox with vuejs
#{{ message }} works in the body or in a tag.
this does not
<input type="text" name="column_name" v-model="reverseMessage" value="{{message}}">
Neither does.
<input type="text" name="column_name" v-model="reverseMessage" value="#{{message}}">

The problem is that you are trying to bind input value multiple variables. Both to reverseMessage (using v-model) and to value (using interpolation).
Please remove value="{{message}}" and just set reverseMessage variable - this should update the input view.
<input type="text" name="column_name" v-model="reverseMessage"/>
and then
this.reverseMessage = "my new input value"
You cannot bind input to many variables in the template itself. Use watchers or computed properties if you really need this.

Related

how to get the form name of current input text onchange in angular 2

I have scenario where I am changing the input text, i have multiple forms and one input within each form so i want to get the current form name whose input i am changing. how to do this in angular 2??
Below is my code for child component
<form #form1="NgForm" novalidate>
<input id="phoneNumber" type="text" placeholder="phoneNumber" class="validate"/>
</form>
<form #form2="NgForm" novalidate>
<input id="mobileNumber" type="text" placeholder="mobileNumber" class="validate"/>
</form>
Now suppose i am adding mobile number i want its form name. How to do this angular 2?? This is i want to access in parent component I am accessing the child component form using #ViewChildren and i am able to access the form manually but i want access dynamically with respect to the input i am accessing ..
In Angular you have two choices use dynamic forms or template driven forms,
your choice is dynamic forms using #form1="NgForm"
Angular dynamic-form
In your code you forgot the '[formControlName]' directive on the inputs, when you have those you can access the form from your component code like:
Component:
this.form1.valueChanges.subscribe(data => console.log('Form changes', data));
HTML:
<form #form2="NgForm" novalidate>
<input [formControlName]="mobileNumber" type="text" placeholder="mobileNumber" class="validate"/>
</form>
I am able to get the current form valid invalid in parent form by passing index as input to child form and emitting the same in parent form...

Testing form input text value

I am testing the following form in my html :
<form wicket:id="form">
<input type="text" wicket:id="input"/>
<input type="submit"/>
</form>
The default value is null and in my test I tried to change it to something and check if I have really changed the field as following:
formTester.setValue(formTester.getForm().get("input"), "randomText");
Assert.assertEquals("randomText", formTester.getTextComponentValue("input"));
However the test is not successful because the field expected <[randomText]> but was: [].Any ideas why the setting doesn't work?
You need to call FormTester#submit() after setting the values of the FormComponents.

Unable to keep the static data for the input type fields in angular material

How to make a default static value for input in material design?
<input type="text" value="xyz" />
but in material design angular I am unable to keep the static value like value="xyz
<md-input-container>
<label>Start date</label>
<input ng-model="agg.startDate" value="xyz">
</md-input-container>"
value xyz is not affected in this case.
In your controller create a variable named agg.startDate using the $scope variable, like following code to set the value of input field
$scope.agg = {startDate: 'xyz'};
check this fiddle link

angularjs form can not refer to input control when input name is array

I encounter a problem when testing form validation with angularjs
According to angularjs form guide,
an input control that has the ngModel directive holds an instance of NgModelController. Such a control instance can be published as a property of the form instance using the name attribute on the input control.
I created test code at plunker, it all works fine untill I change the input name from
<input type="number" name="age" ng-model="user.age" max="100" required>
<p>{{form1.age.$error}}</p>
to
<input type="number" name="user[age]" ng-model="user.age" max="100" required>
<p>{{form1.user[age].$error}}</p>
Does this mean angular can not recognize array syntax in form input?
The problem for me is I want to keep the normal form submission flow and only use angular for form validation, so I need to keep form input as array to work with the backend form handling
It has nothing to do with Angular. It is a syntactic JS error.
If you want to reference a property named user[age], you should do it like this:
form1['user[age]'].$error
form1.user[age] is incorrectly interpreted as (form1.user)[age]

How to have both a default value and a set value in codeigniter forms?

I have a form in codeigniter and would like to have a default value for my input as well as the set_value().
This is my input:
echo form_input('job_position',set_value('job_position'));
I have a set value in place and working but how can I add a default value of '12'?
You can set a default if the value is empty.
From the codeigniter site:
set_value()
Permits you to set the value of an input form or textarea. You must
supply the field name via the first parameter of the function. The
second (optional) parameter allows you to set a default value for the
form. Example:
<input type="text" name="job_position" value="<?php echo set_value('job_position', '12'); ?>" size="50" />
The above form will show "12" when loaded for the first time.
Another Scenario where you can use both set_value and default value:
The set_value() function just sets the value. This function is more useful to preserve the input values when you submit a form with validation errors. So that the user need not to re-enter the fields.
This function has second optional parameter allows you to set a default value for the form.
But If you want to populate your default value if you are using the same form for both editing and adding the data.
<input type="text" name= "name" value = "<?php if($form['name']) echo $form['name']; else echo set_value('name');
The above statement will sets the value if you are adding the values in form. If you are editing the form it simply display the captured value from the database or post data.