I am using formArray to display dynamic data in table and its working as expected, but I am unable to apply the required field validation. I want to validate this table so that no null entry can be save.
In template:
<form *ngIf="userForm" [formGroup]="userForm">
<table>
<tbody formArrayName="order">
<ng-container *ngFor="let orderLine of properties; let i=index" [formGroupName]="i">
<tr>
<td class="fieldspacing">
<input class="form-control" formControlName="propertyName"
[readOnly]="orderLine.IsReadOnly" type="text">
<ng-container *ngIf="order.get('propertyName').hasError('required')">
<span class="errorMsg">Property name cannot be null</span>
</ng-container>
</td>
<td class="fieldspacing">
<select class="form-control selectwidth" formControlName="propertyType" type="text"
(change)="valueChange(i)">
<option *ngFor="let type of propertyTypes" value="{{type.Id}}">{{type.TypeName}}
</option>
</select>
</td>
<div *ngIf="orderLine.PropertyTypeId == 4">
<td class="fieldspacing">
<input type="checkbox" formControlName="readOnly" (change)="handleSelected($event,i)"><label> Has
Parent</label>
</td>
<td class="fieldspacing" *ngIf="orderLine.IsReadOnly || contentEditable">
<select class="form-control selectwidth" formControlName="parentProperty" type="text">
<option *ngFor="let parent of properties" [value]="parent.ParentHierarchyPropertyId">
{{parent.ParentHierarchyPropertyName}}
</option>
</select>
</td>
</div>
</tbody>
</table>
<button (click)="saveUserAdditionalProperties()" type="submit"
class="mt-4 btn btn-primary">Save</button>
</form>
In controller
public properties: any = [
{
"Id": "0012",
"PropertyType": null,
"PropertyTypeId": 4,
"IsReadOnly": true,
"DisplayOrder": 0,
"PropertyName": "Gender",
"ParentHierarchyPropertyId": null,
"ParentHierarchyPropertyName": null,
},
{
"Id": "1234",
"PropertyType": null,
"PropertyTypeId": 4,
"IsReadOnly": false,
"DisplayOrder": 1,
"PropertyName": "save",
"ParentHierarchyPropertyId": null,
"ParentHierarchyPropertyName": null,
},
];
loadUserProperties() {
this.userForm = this.getForm();
}
getForm(): FormGroup {
return new FormGroup({
order: new FormArray(this.properties.map(this.getFormGroupForUserProperty)),
});
}
getFormGroupForUserProperty(userProperty: any) {
let formGroup: FormGroup = new FormGroup({
propertyName: new FormControl(userProperty.PropertyName,Validators.required),
propertyType: new FormControl(userProperty.PropertyTypeId),
parentProperty: new FormControl(userProperty.ParentHierarchyPropertyId),
readOnly: new FormControl(userProperty.IsReadOnly)
});
You need to use it for formArray
formArray: FormArray;
constructor(
private _formBuilder: FormBuilder
) {}
this.formArray = this._formBuilder.array([]);
new Array(LENGTH_NUMBER).fill(1).forEach(() => {
this.formArray.push(this._formBuilder.group({
FORMCONTROLNAME_ONE: ["", Validators.required],
FORMCONTROLNAME_TWO: ["", Validators.required],
FORMCONTROLNAME_THREE: ["", Validators.required]
}))
});
HTML side
<ng-container *ngFor="let formGroup of formArray.controls;">
<div [formGroup]="formGroup">
<input formControlName="FORMCONTROLNAME_ONE">
<input formControlName="FORMCONTROLNAME_TWO">
<input formControlName="FORMCONTROLNAME_THREE">
</div>
</ng-container>
Obviously you can apply a filter on the userForm that
if(userForm.value.order.length!==0){
// submit
}else{
// not submit
}
Related
this is the class i use
export class Product
{
id: string;
title: string;
description:string;
numbersOfBuyers2Price: {[key: number]: number};
category: string;
img: string;
endDate: number;
}
the function that save the new product
onSaveProduct()
{
if (this.form.invalid) {
return;
}
if (this.mode === 'create')
{
this.productService.addProduct(
this.form.value.title,
this.form.value.description,
this.form.value.priceArray,
this.form.value.category,
this.form.value.img,
this.form.value.endDate
);
}
}
the html for create to new product
<form [formGroup]="form" (submit)="onSaveProduct()">
<table class="example-full-width" cellspacing="0"><tr>
<td>
<mat-label>Title:</mat-label>
<input formControlName="title" matInput>
</td>
<td>
<mat-label>Category:</mat-label>
<input matInput formControlName ="category">
</td>
<td>
<mat-label>IMG:</mat-label>
<input matInput formControlName ="img">
</td>
<td>
<mat-label>End Date:</mat-label>
<input matInput formControlName ="endDate">
</td>
</tr></table>
<button mat-raised-button color="accent" type="submit">Save product</button>
</form>
i'm trying to adding multiple keyValues to numbersOfBuyers2Price using the html component,
i found only how to display them with *ngFor
You could add UI to the HTML template to add new key value pairs to a member of your component clas. Then when the form is submitted you can use that in your onSaveProduct function.
HTML
<td>
<mat-label>New Buyers2Price:</mat-label>
<input matInput [formControl]="newKey">
<input matInput [formControl]="newValue">
<button (click)="addKeyValue()">Add</button>
</td>
TS
class YourComponent {
private buyer2price: {[key: number]: nuber} = {};
public newKey = new FormControl('');
public newValue = new FormControl('');
public function addKeyValue() {
this.buyer2price[this.newKey.value] = this.newValue.value;
}
I want to add multiple fields on the click of a button 'Add Answer' and all these values should be stored in an array.
So, each time on clicking this button 5 input fields should be generated and these values should be stored in an array as information about a single item.
I tried using formBuilder but it wasn't working then also tried a form group approach but couldn't implement it. I think it can be done using form group approach.
Content.component.ts:
export class ContentComponent implements OnInit {
questionForm: FormGroup;
aa = false;
ccc = true;
flag = 0;
constructor() { }
ngOnInit() {
this.questionForm = new FormGroup({
'course': new FormControl(null, Validators.required),
'topic': new FormControl(null),
'videos': new FormControl(null),
'quest': new FormControl(null, Validators.required),
'typee': new FormControl(null, Validators.required),
// name: new FormControl(),
// sName: new FormControl(),
'answerOptions': new FormArray([]),
'answerOptions2': new FormArray([]),
'answerOptions3': new FormArray([]),
'answerOptions4': new FormArray([]),
'answerOptions5': new FormArray([]),
'answerOptionsC': new FormArray([]),
'answerOptionsC2': new FormArray([]),
'answerOptionsC3': new FormArray([]),
'answerOptionsC4': new FormArray([]),
'answerOptionsC5': new FormArray([]),
'answerOptionsI': new FormArray([]),
});
this.questionForm.setValue({
'course': 'c1',
'topic': 't2',
'videos': 'v3',
'quest': '',
'typee': '',
'answerOptions': [],
'answerOptions2': [],
'answerOptions3': [],
'answerOptions4': [],
'answerOptions5': [],
'answerOptionsC': [],
'answerOptionsC2': [],
'answerOptionsC3': [],
'answerOptionsC4': [],
'answerOptionsC5': [],
'answerOptionsI': []
});}
onAddAns() {
if (this.flag === 1) {
const controlI = new FormControl(null, Validators.required);
(<FormArray>this.questionForm.get('answerOptionsI')).push(controlI);
} else if (this.flag === 2) {
// (<FormArray>this.questionForm.get('answerOptions')).push(
// new FormGroup({
// 'name': new FormControl(null),
// 'sName': new FormControl(null)
// })
// );
} else if (this.flag === 3) {
const controlC = new FormControl(null, Validators.required);
(<FormArray>this.questionForm.get('answerOptionsC')).push(controlC);
(<FormArray>this.questionForm.get('answerOptionsC2')).push(controlC);
(<FormArray>this.questionForm.get('answerOptionsC3')).push(controlC);
(<FormArray>this.questionForm.get('answerOptionsC4')).push(controlC);
(<FormArray>this.questionForm.get('answerOptionsC5')).push(controlC);
}}
dropChanged(val: any) {
this.questionForm.get('typee').disable();
console.log(val);
this.ccc = false;
if (val === 'text') {
this.flag = 1;
} else if (val === 'radio') {
this.flag = 2;
} else if (val === 'check') {
this.flag = 3;
} }
onSubmit() {
console.log(this.questionForm);}}
Content.component.html:
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-10 col-md-8 col-sm-offset-1 col-md-offset-2">
<form [formGroup]="questionForm" (ngSubmit)="onSubmit()">
<div class="form-group">
<label for="type1">Select Course:</label>
<select
id="type1"
formControlName="course"
class="form-control">
<option value="c1">Data Handling</option>
<option value="c2">Data Processing</option>
<option value="c3">Data Manipulation</option>
</select>
</div>
<div class="form-group">
<label for="type2">Select Topic:</label>
<select
id="type2"
formControlName="topic"
class="form-control">
<option value="t1">Topic 1</option>
<option value="t2">Topic 2</option>
<option value="t3">Topic 3</option>
</select>
</div>
<div class="form-group">
<label for="type2">Select Video:</label>
<select
id="type2"
formControlName="videos"
class="form-control">
<option value="v1">Video 1</option>
<option value="v2">Video 2</option>
<option value="v3">Video 3</option>
</select>
</div>
<div class="form-group">
<label for= "questio">Question:
</label>
<input
type="text"
id= "questio"
formControlName="quest"
class="form-control">
<span
*ngIf="!questionForm.get('quest').valid && questionForm.get('quest').touched"
class="help-block">
<span *ngIf="questionForm.get('quest').errors['required']">This field is required!</span>
</span>
</div>
<div class="form-group">
<label for="type">Type of question</label>
<select
[disabled]="aa"
id="type"
formControlName="typee"
(change)="dropChanged($event.target.value)"
class="form-control">
<option value="text">Input type</option>
<option value="radio">Radio Button</option>
<option value="check">Checkbox</option>
</select>
</div>
<h4>Answers</h4>
<button
class="btn btn-default"
type="button"
(click)="onAddAns()">Add Answers</button>
<div class="form-group" id="ip1">
<!--*ngFor="let answerOptionControl of questionForm.get('answerOptions').controls; let i = index"-->
<!--formGroupName="i">-->
<!--Solution:<input type="text" class="form-control" [formControlName]='name'>-->
<!--Hint:<input type="text" class="form-control" [formControlName]="sName">-->
<hr>
</div>
<div class="form-group" id="ip2"
*ngFor="let answerOptionControlC of questionForm.get('answerOptionsC').controls; let a = index
let answerOptionControlC2 of questionForm.get('answerOptionsC2').controls; let b = index
let answerOptionControlC3 of questionForm.get('answerOptionsC3').controls; let c = index
let answerOptionControlC4 of questionForm.get('answerOptionsC4').controls; let d = index
let answerOptionControlC5 of questionForm.get('answerOptionsC4').controls; let e = index">
Solution:<input type="text" class="form-control" [formControlName]="a">
Hint:<input type="text" class="form-control" [formControlName]="b">
Status:<input type="text" class="form-control" [formControlName]="c">
link:<input type="text" class="form-control" [formControlName]="d">
Message:<input type="text" class="form-control" [formControlName]="e">
<hr>
</div>
<div class="form-group" id="ip3"
*ngFor="let answerOptionControlI of questionForm.get('answerOptionsI').controls; let f = index">
Keyword:<input type="text" class="form-control" formControlName="f">
<hr>
</div>
<hr>
<button class="btn btn-primary" type="submit" [disabled]="ccc" (click)="onSubmit()">Submit</button>
</form>
</div>
So, right now only for the option checkbox the application is working but some error is there of controls.
I know this approach is wrong that is why I want to do it using form-group.
This is the result of this code and the error along with it.
Your issue is that you forgot the [] around formControlName in the following code (I added it below):
<div class="form-group" id="ip3"
*ngFor="let answerOptionControlI of questionForm.get('answerOptionsI').controls; let f = index">
Keyword:<input type="text" class="form-control" [formControlName]="f">
<hr>
</div>
Therefore, instead of looking for the control at the index f, it is looking for a control named 'f', which does not exist.
I want to post data from autocomplete material.
My ts code, like this. I used registerUserForm formgroup.
export class AddUserFormComponent implements OnInit {
countryes: Country[];
registerUserForm: FormGroup;
filteredOptionsCountry: Observable<Country[]>;
myControlCountry: FormControl = new FormControl();
constructor(private fb: FormBuilder,
private router: Router,
private cs: CountryService)
{
this.registerUserForm = new FormGroup({
'username': new FormControl(),
'email': new FormControl(),
'country_id': new FormControl(),
});
}
ngOnInit() {
this.registerUserForm = this.fb.group({
'username': ['', Validators.compose([Validators.required, Validators.minLength(5)])],
'country_id': ['', Validators.required],
'email': ['', [Validators.required, ValidationService.emailValidation]],
});
this.filteredOptionsCountry = this.myControlCountry.valueChanges.pipe(
startWith(''),
map(val => this.filterCountry(val))
);
this.cs.getAllCountry().subscribe(
countryes => {
this.countryes = countryes.map((country) => {
return new Country(country);
});
}
);
}
onRegisterUser() {
this.loading = true;
this.invalidInputs = true;
let newUser = new User(
this.registerUserForm.value
);
this.userService.createUser(newUser).subscribe(
);
}
onCancel() {
this.router.navigate(['/main/users']);
}
//Country
filterCountry(val: string): Country[] {
if (val) {
let filterValue = val.toLowerCase();
console.log(this.countryes)
return this.countryes.filter(country => country.name.toLowerCase().startsWith(filterValue));
}
return this.countryes;
}
}
my html code. In this code i have 3 parameters, only email and username i can post, country_id post empty
<form [formGroup]="registerUserForm" (ngSubmit)="onRegisterUser()" class="col s12" materialize>
<div class="row">
<div class="input-field col s12">
<input formControlName="username" id="username" type="text" class="validate" placeholder="Enter Username" minlength="3" maxlength="20"
required="" [ngClass]="{invalid: invalidInputs}">
</div>
</div>
<div class="row">
<div class="input-field col s12">
<input formControlName="email" id="email" type="email" class="validate" placeholder="Enter Email" required="" aria-required="true"
[ngClass]="{invalid: invalidInputs}">
</div>
</div>
<!-- Autocomplete Country Material-->
<input formControlName="country_id" id="country_id" matInput placeholder="Select Country" aria-label="State" [matAutocomplete]="auto"
autoActiveFirstOption [formControl]="myControlCountry">
<mat-autocomplete #auto="matAutocomplete">
<mat-option *ngFor="let country of filteredOptionsCountry | async" [value]="country.name">
{{ country.name }}
</mat-option>
</mat-autocomplete>
<!-- End Autocomplete Country -->
<div id="register_user_button_container" class="row">
<button id="register_user_button" type="submit" class="btn waves-effect waves-light">
Register
</button>
<button id="cancel_button" (click)="onCancel()" class="btn waves-effect waves-light grey lighten-4 black-text">
Cancel
</button>
</div>
</form>
Can you suggest me, how to used this FormControl inside registerUserForm ? Or, something solution.
Your code is litteral chaos.
First, group everything in a single form.
registerUserForm: FormGroup;
Then, instantiate your form only once, you don't need to do it more.
constructor() {
this.registerUserForm = this.fb.group({
username: ['', [Validators.required, Validators.minLength(5)]],
country_id: ['', Validators.required],
email: ['', [Validators.required, ValidationService.emailValidation]],
myControlCountry: ''
});
}
Next, use a getter to get your countries. (This is one of the many ways)
countries: Country[];
get filteredCountries() {
const query = this.registerUserForm.get('country_id').value;
return query ?
this.countries.filter(c => c.name.toLowerCase().includes(query.toLowerCase)) :
this.countries;
}
Now you must bind it to your HTML :
<mat-option *ngFor="let country of filteredCountries" [value]="country.name">
{{ country.name }}
</mat-option>
How to build a JSON data using ngModel which is the component is inside form and the table is outside form, which is i have ngModel repeated using ngFor in the table. Here is how my html looked like :
app.component.html :
<div>
<form>
<div class="form-group row">
Nama Role : <input type="text" [(ngModel)]="nama_role" [ngModelOptions]="{standalone: true}" class="form-control" placeholder="Nama Role" pattern="[a-zA-Z-0-9. ]+">
</div>
</form>
<div>
Pilih Hak :
<table class="mytable">
<tr>
<th>No</th>
<th>Kode Aplikasi</th>
<th>Nama Aplikasi</th>
<th>View?</th>
<th>Insert?</th>
<th>Edit?</th>
<th>Delete?</th>
</tr>
<tr *ngFor="let sources of source; let a=index">
<td>{{a + 1}}</td>
<td>{{sources.KODE_APPLICATION}}</td>
<td>{{sources.NAMA_APPLICATION}}</td>
<td><input type="checkbox" [(ngModel)]="sources.hak_akses" (change)="toggle($event)" /> {{sources.HAK_AKSES}}</td>
<td><input type="checkbox" [(ngModel)]="sources.hak_insert" (change)="toggle($event)" />{{sources.HAK_INSERT}}</td>
<td><input type="checkbox" [(ngModel)]="sources.hak_edit" (change)="toggle($event)" />{{sources.HAK_EDIT}}</td>
<td><input type="checkbox" [(ngModel)]="sources.hak_delete" (change)="toggle($event)" />{{sources.HAK_DELETE}}</td>
</tr>
</table>
</div>
<div class="row show-grid">
<button class="btn btn-primary" (click)="save()">Save</button>
</div>
</div>
and here is my app.component.ts
export class frmInputMasterRole {
public sKodeRole: any;
sStorage:any;
hak_akses:any;
hak_insert:any;
hak_edit:any;
hak_delete:any;
private busyloadevent: IBusyConfig = Object.assign({}, BUSY_CONFIG_DEFAULTS);
marked = false;
constructor(private frmInputMasterRoleService: FrmInputMasterRoleService, protected router: Router) {
this.sKodeRole = 'Auto Generated';
this.sStorage = sessionStorage.getItem('mAuth');
this.sStorage = JSON.parse(this.sStorage);
this.busyloadevent.busy = this.frmInputMasterRoleService.getListRoleDetail().then(
data => {
this.source = data;
console.log(data);
for (var i of this.source) {
this.hak_akses = i.HAK_AKSES;
}
},
err => {
console.log(err);
}
}
);
}
save(){
console.log(this.hak_akses);
}
toggle(e){
console.log(e.target.checked)
}
cancel(){
this.router.navigate(['/pages/master/rolelist']);
}
}
and here is my JSON data when consume my REST API, which is looped with ngFor in source type :
[
{
"No":"1",
"KODE_APPLICATION":"APPL00001",
"NAMA_APPLICATION":"Master Bass",
"HAK_AKSES":0,
"HAK_INSERT":0,
"HAK_EDIT":0,
"HAK_DELETE":0
},
{
"No":"2",
"KODE_APPLICATION":"APPL00002",
"NAMA_APPLICATION":"Master Customer",
"HAK_AKSES":0,
"HAK_INSERT":0,
"HAK_EDIT":0,
"HAK_DELETE":0
},
{
"No":"3",
"KODE_APPLICATION":"APPL00003",
"NAMA_APPLICATION":"Master Teknisi",
"HAK_AKSES":0,
"HAK_INSERT":0,
"HAK_EDIT":0,
"HAK_DELETE":0
}
]
what i want is i want to build JSON data that looked like this when the last row is checked :
{
"nama_role":test,
"details": [{
"KODE_APPLICATION":"APPL00003",
"NAMA_APPLICATION":"Master Teknisi",
"HAK_AKSES":1,
"HAK_INSERT":0,
"HAK_EDIT":0,
"HAK_DELETE":0
}]
}
how do i do this? i dunno where to start since there is a table with ngModel that looped with ngFor
Code is attached below:
#Component({
selector: 'my-app',
template: `<form>
<div class="form-group row">
Nama Role : <input type="text" [(ngModel)]="nama_role" [ngModelOptions]="{standalone: true}" class="form-control" placeholder="Nama Role" pattern="[a-zA-Z-0-9. ]+">
</div>
</form>
<table>
<tr>
<th>No</th>
<th>Kode Aplikasi</th>
<th>Nama Aplikasi</th>
<th>View?</th>
<th>Insert?</th>
<th>Edit?</th>
<th>Delete?</th>
</tr>
<tr *ngFor="let sources of source; let a=index">
<td>{{sources.KODE_APPLICATION}}</td>
<td>{{sources.NAMA_APPLICATION}}</td>
<td><input type="checkbox" [checked]="sources.HAK_AKSES" [(ngModel)]="sources.HAK_AKSES" (change)="toggle(a, sources.HAK_AKSES, \'HAK_AKSES\')"/> {{sources.HAK_AKSES}}</td>
<td><input type="checkbox" [checked]="sources.HAK_INSERT" [(ngModel)]="sources.HAK_INSERT" (change)="toggle(a, sources.HAK_INSERT, \'HAK_INSERT\')" />{{sources.HAK_INSERT}}</td>
<td><input type="checkbox" [checked]="sources.HAK_EDIT" [(ngModel)]="sources.HAK_EDIT" (change)="toggle(a, sources.HAK_EDIT, \'HAK_EDIT\')" />{{sources.HAK_EDIT}}</td>
<td><input type="checkbox" [checked]="sources.HAK_DELETE" [(ngModel)]="sources.HAK_DELETE" (change)="toggle(a, sources.HAK_DELETE, \'HAK_DELETE\')" />{{sources.HAK_DELETE}}</td>
</tr>
</table>
<div class="row show-grid">
<button class="btn btn-primary" (click)="save()">Save</button>
</div>
<custom-comp [myFunc]="handleClick()"></custom-comp>
`
})
export class MainComponent {
source = [];
ngOnInit() {
this.source = [{
"No":"1",
"KODE_APPLICATION":"APPL00001",
"NAMA_APPLICATION":"Master Bass",
"HAK_AKSES":1,
"HAK_INSERT":1,
"HAK_EDIT":1,
"HAK_DELETE":0
},
{
"No":"2",
"KODE_APPLICATION":"APPL00002",
"NAMA_APPLICATION":"Master Customer",
"HAK_AKSES":0,
"HAK_INSERT":0,
"HAK_EDIT":0,
"HAK_DELETE":0
},
{
"No":"3",
"KODE_APPLICATION":"APPL00003",
"NAMA_APPLICATION":"Master Teknisi",
"HAK_AKSES":1,
"HAK_INSERT":0,
"HAK_EDIT":0,
"HAK_DELETE":0
}
];
}
save() {
let payload = {
"nama_role": this.nama_role,
"details": this.source
};
console.log(payload);
}
toggle(index, val, key) {
this.source[index][key] = val ? 1 : 0;
}
}
Cheers!
I am trying to set an initial value for a select, but not showing in the view.
My jsx:
var SelectOKNO = React.createClass({
render() {
return (
<div>
<select className="selectpicker" value={this.props.value}
onChange={this.props.onChange.bind(this)}>
<option value=""></option>
<option value="OK">OK</option>
<option value="NO">NO</option>
</select>
</div>
)
}
});
var Detalle = React.createClass({
getInitialState: function() {
return({
ID:'',
UREFValue: '',
URCorrectoValue: '',
ConcordanciaValue: '',
PruebasValue: '',
EmergenciasValue: '',
ComentarioValue: '',
EstadoValue:'',
rec_fecha_aprobacion:'',
rec_aplica_control: '',
rec_auditor: ''
});
},
handleChange: function (key) {
return function (e) {
var state = {};
state[key] = e.target.value;
this.setState(state);
}.bind(this);
},
componentDidMount: function() {
$.ajax({
url: 'url',
data: { //Passing data
id: $("#hdnID").val()
},
dataType: 'json',
cache: false,
success: function(data) {
this.setState({
ID:data.rec_id,
UREFValue:data.rec_inconveniente_usuario_ref,
URCorrectoValue:data.rec_usuario_ref_correcto,
ConcordanciaValue:data.rec_concordancia_doc,
PruebasValue:data.rec_pruebas,
EmergenciasValue:data.rec_emergencia,
ComentarioValue:data.rec_comentario,
EstadoValue: data.rec_estado,
rec_fecha_aprobacion:data.rec_fecha_aprobacion,
rec_aplica_control: data.rec_aplica_control,
rec_auditor: data.rec_auditor
});
}.bind(this),
error: function(xhr, status, err) {
}.bind(this)
});
},
render() {
return (
<form onSubmit={this.handleSubmit}>
<br/>
<table className="table borderless">
<tr className ="row">
<td>Usuario Referente:
<SelectOKNO value={this.state.UREFValue} onChange={this.handleChange('UREFValue').bind(this)}/>
</td>
<td>UR Correcto:
<textarea rows="3" className="form-control noresize" value={this.state.URCorrectoValue} onChange={this.handleChange('URCorrectoValue')} />
</td>
</tr>
<tr className ="row">
<td>Concordancia:
<SelectOKNO value={this.state.ConcordanciaValue} onChange={this.handleChange('ConcordanciaValue')}/>
</td>
<td>Pruebas:
<SelectOKNO value={this.state.PruebasValue} onChange={this.handleChange('PruebasValue')}/>
</td>
</tr>
<tr className ="row">
<td>Emergencias:
<SelectOKNO value={this.state.EmergenciasValue} onChange={this.handleChange('EmergenciasValue').bind(this)}/>
</td>
<td>Comentario:
<textarea rows="3" className="form-control noresize" value={this.state.ComentarioValue} onChange={this.handleChange('ComentarioValue')} />
</td>
</tr>
<tr className ="row">
<td>
<select className="selectpicker" value={this.state.EstadoValue}
onChange={this.handleChange('EstadoValue')}>
<option value="Abierto">Abierto</option>
<option value="EN_PROCESO">En Proceso</option>
<option value="CON_INCONVENIENTES">Con Inconvenientes</option>
<option value="COMPLETO">Completo</option>
</select>
</td>
<td>
<button type="submit" className="btn btn-default">Guardar</button>
</td>
</tr>
</table>
</form>
)
}
});
When page loads, all the select shows value like ''.
But in debug view of chrome I can see the value
How to set selected on options elements. Also, check what that means in React.
Finally, some nice libraries:
react-select and
react-bootstrap