Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

angular reactive input required based on previous value

// attr declarations
fieldOne = new FormControl('',[]); // initial value and validators inside array
fieldTwo = new FormControl('', []); // initialValue and validators

// ngOnInit
fieldOne.valueChanges.
.pipe(
debounceTime(100),   // dalay after every change to update your validations
distinctUntilChanged(), // only update validators when value change
tap(value => {

// depend on your options you can use switch here
   if(value === 'Adhaar number'){
    this.fieldTwo.setValidators([Validators.required,Validators.maxLength(12)]);
    this.fieldTwo.updateValueAndValidity();
  } else 
 if(value === 'PAN number'){
    this.fieldTwo.setValidators([Validators.required,Validators.maxLength(10)]);
    this.fieldTwo.updateValueAndValidity();
  } else {
this.fieldTwo.setValidators([Validators.required]);
    this.fieldTwo.updateValueAndValidity();
}
})

)
.subscribe()
Comment

PREVIOUS NEXT
Code Example
Javascript :: Codewars hello world 
Javascript :: ryan dahl 
Javascript :: jquery on hover event 
Javascript :: cursor to pointer in react 
Javascript :: how to shuffle an array in js 
Javascript :: date of birth validation in yup 
Javascript :: fill checkbox javascript 
Javascript :: object get property with max value javascript 
Javascript :: jquery move element 
Javascript :: javascript before reload page alert 
Javascript :: multi-stage Dockerfile for Node.js 
Javascript :: how to format numbers as currency string js 
Javascript :: react-native shadow generator 
Javascript :: move an element into another jquery 
Javascript :: Setting object properties in C# from Javascript code 
Javascript :: js get all object styles 
Javascript :: js take last item in array 
Javascript :: exit application node js 
Javascript :: truthy or falsy value javascript 
Javascript :: create array initialize size javascript 
Javascript :: remove first and last character from string javascript 
Javascript :: creating a custom router class in backbone 
Javascript :: javascript go to page 
Javascript :: increase font size in jsx 
Javascript :: set background image in material ui 
Javascript :: jquery toggle class 
Javascript :: dynamics js search another entity 
Javascript :: javascript new date zero time 
Javascript :: load js file 
Javascript :: how to get aria expanded value in javascript 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =