How can we set sync validation null when adding async angular validation?How to add async validation without adding any other validators?Angular - Set headers for every requestAngular/RxJs When should I unsubscribe from `Subscription`custom async validation not working when returning a promiseHow to pass extra param to an async validator (reactive forms) in Angular?Angular 5 form component causing Error: 'RangeError: Maximum call stack size exceeded 'ck editor reactive form angular 6 not workingNot able to store dynamic FormArray in FormGroupForm-Validation not working properly AngularHow to add async validation without adding any other validators?

More than three domains hosted on the same IP address

Why has Marx's "Das Kapital" been translated to "Capital" in English and not "The Capital"

Is it right to use the ideas of non-winning designers in a design contest?

Bit floating sequence

How to best explain that you are taking pictures in a space for practice reasons?

Owner keeps cutting corners and poaching workers for his other company

Do you need to burn fuel between gravity assists?

Examples where "thin + thin = nice and thick"

How to accelerate progress in mathematical research

Why did Tony's Arc Reactor do this?

How do you say "to hell with everything" in French?

Is mountain bike good for long distances?

How do I write a vertically-stacked definition of a sequence?

How do English-speaking kids loudly request something?

What is the "Brake to Exit" feature on the Boeing 777X?

How do German speakers decide what should be on the left side of the verb?

Friend is very nit picky about side comments I don't intend to be taken too seriously

How to apply a register to a command

Why does low tire pressure decrease fuel economy?

Was Rosie the Riveter sourced from a Michelangelo painting?

How strong is aircraft-grade spruce?

Is every sentence we write or utter either true or false?

How many attacks exactly do I get combining Dual Wielder feat with Two-Weapon Fighting style?

Laptop failure due to constant fluctuation of AC frequency and voltage



How can we set sync validation null when adding async angular validation?


How to add async validation without adding any other validators?Angular - Set headers for every requestAngular/RxJs When should I unsubscribe from `Subscription`custom async validation not working when returning a promiseHow to pass extra param to an async validator (reactive forms) in Angular?Angular 5 form component causing Error: 'RangeError: Maximum call stack size exceeded 'ck editor reactive form angular 6 not workingNot able to store dynamic FormArray in FormGroupForm-Validation not working properly AngularHow to add async validation without adding any other validators?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I am trying to create a control with async validation and I don't want sync validation:



Creating form using formBuilder.



 this.myForm = this.fb.group( 
someControl: new FormControl(
"",
null,
[this.valueUnique.bind(this)]
))


If I keep sync validation parameter as Validators.required then I get no error.



Error:




ERROR Error: Expected validator to return Promise or Observable.
at toObservable (forms.js:603)
at Array.map ()
at FormControl.asyncValidator (forms.js:591)
at FormControl.push../node_modules/@angular/forms/fesm5/forms.js.AbstractControl._runAsyncValidator
(forms.js:2535)
at FormControl.push../node_modules/@angular/forms/fesm5/forms.js.AbstractControl.updateValueAndValidity
(forms.js:2508)
at FormControl.push../node_modules/@angular/forms/fesm5/forms.js.AbstractControl._updateTreeValidity
(forms.js:2523)
at forms.js:2522
at forms.js:3309
at Array.forEach ()
at FormGroup.push../node_modules/@angular/forms/fesm5/forms.js.FormGroup._forEachChild
(forms.js:3309)




Validator function:



 /**
* Validator to checking existance/uniqueness
* of entered value
* @param control
*/
valueIsUnique(control: AbstractControl): Promise<ValidationErrors|null> | null
if (control && (control.value !== null && control.value !== undefined))
return new Promise((resolve, reject) =>
this.service.checkValueExists(control.value).subscribe(res =>

if (res && res['data'])
resolve(
unique: true
);

else
resolve(null);


,
err=>

resolve(null);
);
);











share|improve this question


























  • Are you sure that this.valueUnique.bind(this) is returning an Observable or Promise? Because hat is what the error says, your binding to the function valueUnique is not returning this type.

    – Sam Vloeberghs
    Mar 28 at 7:08











  • @SamVloeberghs thanks, yes my async validator returning promise. I have updated question. Also added similar post yesterday: stackoverflow.com/questions/55375700/… If I add sync validation = Validators.required then error does not come.

    – Harsimer
    Mar 28 at 8:02







  • 1





    your if should be inside the return new Promise. You have a potential case here that you are not return a promise.

    – Sam Vloeberghs
    Mar 28 at 8:24











  • @SamVloeberghs Ok thanks. Let me check and I will update you.

    – Harsimer
    Mar 28 at 8:41











  • @SamVloeberghs How can I return promise in that If conditione it is outside new promise?

    – Harsimer
    Mar 28 at 8:57

















0















I am trying to create a control with async validation and I don't want sync validation:



Creating form using formBuilder.



 this.myForm = this.fb.group( 
someControl: new FormControl(
"",
null,
[this.valueUnique.bind(this)]
))


If I keep sync validation parameter as Validators.required then I get no error.



Error:




ERROR Error: Expected validator to return Promise or Observable.
at toObservable (forms.js:603)
at Array.map ()
at FormControl.asyncValidator (forms.js:591)
at FormControl.push../node_modules/@angular/forms/fesm5/forms.js.AbstractControl._runAsyncValidator
(forms.js:2535)
at FormControl.push../node_modules/@angular/forms/fesm5/forms.js.AbstractControl.updateValueAndValidity
(forms.js:2508)
at FormControl.push../node_modules/@angular/forms/fesm5/forms.js.AbstractControl._updateTreeValidity
(forms.js:2523)
at forms.js:2522
at forms.js:3309
at Array.forEach ()
at FormGroup.push../node_modules/@angular/forms/fesm5/forms.js.FormGroup._forEachChild
(forms.js:3309)




Validator function:



 /**
* Validator to checking existance/uniqueness
* of entered value
* @param control
*/
valueIsUnique(control: AbstractControl): Promise<ValidationErrors|null> | null
if (control && (control.value !== null && control.value !== undefined))
return new Promise((resolve, reject) =>
this.service.checkValueExists(control.value).subscribe(res =>

if (res && res['data'])
resolve(
unique: true
);

else
resolve(null);


,
err=>

resolve(null);
);
);











share|improve this question


























  • Are you sure that this.valueUnique.bind(this) is returning an Observable or Promise? Because hat is what the error says, your binding to the function valueUnique is not returning this type.

    – Sam Vloeberghs
    Mar 28 at 7:08











  • @SamVloeberghs thanks, yes my async validator returning promise. I have updated question. Also added similar post yesterday: stackoverflow.com/questions/55375700/… If I add sync validation = Validators.required then error does not come.

    – Harsimer
    Mar 28 at 8:02







  • 1





    your if should be inside the return new Promise. You have a potential case here that you are not return a promise.

    – Sam Vloeberghs
    Mar 28 at 8:24











  • @SamVloeberghs Ok thanks. Let me check and I will update you.

    – Harsimer
    Mar 28 at 8:41











  • @SamVloeberghs How can I return promise in that If conditione it is outside new promise?

    – Harsimer
    Mar 28 at 8:57













0












0








0








I am trying to create a control with async validation and I don't want sync validation:



Creating form using formBuilder.



 this.myForm = this.fb.group( 
someControl: new FormControl(
"",
null,
[this.valueUnique.bind(this)]
))


If I keep sync validation parameter as Validators.required then I get no error.



Error:




ERROR Error: Expected validator to return Promise or Observable.
at toObservable (forms.js:603)
at Array.map ()
at FormControl.asyncValidator (forms.js:591)
at FormControl.push../node_modules/@angular/forms/fesm5/forms.js.AbstractControl._runAsyncValidator
(forms.js:2535)
at FormControl.push../node_modules/@angular/forms/fesm5/forms.js.AbstractControl.updateValueAndValidity
(forms.js:2508)
at FormControl.push../node_modules/@angular/forms/fesm5/forms.js.AbstractControl._updateTreeValidity
(forms.js:2523)
at forms.js:2522
at forms.js:3309
at Array.forEach ()
at FormGroup.push../node_modules/@angular/forms/fesm5/forms.js.FormGroup._forEachChild
(forms.js:3309)




Validator function:



 /**
* Validator to checking existance/uniqueness
* of entered value
* @param control
*/
valueIsUnique(control: AbstractControl): Promise<ValidationErrors|null> | null
if (control && (control.value !== null && control.value !== undefined))
return new Promise((resolve, reject) =>
this.service.checkValueExists(control.value).subscribe(res =>

if (res && res['data'])
resolve(
unique: true
);

else
resolve(null);


,
err=>

resolve(null);
);
);











share|improve this question
















I am trying to create a control with async validation and I don't want sync validation:



Creating form using formBuilder.



 this.myForm = this.fb.group( 
someControl: new FormControl(
"",
null,
[this.valueUnique.bind(this)]
))


If I keep sync validation parameter as Validators.required then I get no error.



Error:




ERROR Error: Expected validator to return Promise or Observable.
at toObservable (forms.js:603)
at Array.map ()
at FormControl.asyncValidator (forms.js:591)
at FormControl.push../node_modules/@angular/forms/fesm5/forms.js.AbstractControl._runAsyncValidator
(forms.js:2535)
at FormControl.push../node_modules/@angular/forms/fesm5/forms.js.AbstractControl.updateValueAndValidity
(forms.js:2508)
at FormControl.push../node_modules/@angular/forms/fesm5/forms.js.AbstractControl._updateTreeValidity
(forms.js:2523)
at forms.js:2522
at forms.js:3309
at Array.forEach ()
at FormGroup.push../node_modules/@angular/forms/fesm5/forms.js.FormGroup._forEachChild
(forms.js:3309)




Validator function:



 /**
* Validator to checking existance/uniqueness
* of entered value
* @param control
*/
valueIsUnique(control: AbstractControl): Promise<ValidationErrors|null> | null
if (control && (control.value !== null && control.value !== undefined))
return new Promise((resolve, reject) =>
this.service.checkValueExists(control.value).subscribe(res =>

if (res && res['data'])
resolve(
unique: true
);

else
resolve(null);


,
err=>

resolve(null);
);
);








angular angular-reactive-forms angular-validation angular-formbuilder






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 8:01







Harsimer

















asked Mar 28 at 6:06









HarsimerHarsimer

1,1834 gold badges20 silver badges58 bronze badges




1,1834 gold badges20 silver badges58 bronze badges















  • Are you sure that this.valueUnique.bind(this) is returning an Observable or Promise? Because hat is what the error says, your binding to the function valueUnique is not returning this type.

    – Sam Vloeberghs
    Mar 28 at 7:08











  • @SamVloeberghs thanks, yes my async validator returning promise. I have updated question. Also added similar post yesterday: stackoverflow.com/questions/55375700/… If I add sync validation = Validators.required then error does not come.

    – Harsimer
    Mar 28 at 8:02







  • 1





    your if should be inside the return new Promise. You have a potential case here that you are not return a promise.

    – Sam Vloeberghs
    Mar 28 at 8:24











  • @SamVloeberghs Ok thanks. Let me check and I will update you.

    – Harsimer
    Mar 28 at 8:41











  • @SamVloeberghs How can I return promise in that If conditione it is outside new promise?

    – Harsimer
    Mar 28 at 8:57

















  • Are you sure that this.valueUnique.bind(this) is returning an Observable or Promise? Because hat is what the error says, your binding to the function valueUnique is not returning this type.

    – Sam Vloeberghs
    Mar 28 at 7:08











  • @SamVloeberghs thanks, yes my async validator returning promise. I have updated question. Also added similar post yesterday: stackoverflow.com/questions/55375700/… If I add sync validation = Validators.required then error does not come.

    – Harsimer
    Mar 28 at 8:02







  • 1





    your if should be inside the return new Promise. You have a potential case here that you are not return a promise.

    – Sam Vloeberghs
    Mar 28 at 8:24











  • @SamVloeberghs Ok thanks. Let me check and I will update you.

    – Harsimer
    Mar 28 at 8:41











  • @SamVloeberghs How can I return promise in that If conditione it is outside new promise?

    – Harsimer
    Mar 28 at 8:57
















Are you sure that this.valueUnique.bind(this) is returning an Observable or Promise? Because hat is what the error says, your binding to the function valueUnique is not returning this type.

– Sam Vloeberghs
Mar 28 at 7:08





Are you sure that this.valueUnique.bind(this) is returning an Observable or Promise? Because hat is what the error says, your binding to the function valueUnique is not returning this type.

– Sam Vloeberghs
Mar 28 at 7:08













@SamVloeberghs thanks, yes my async validator returning promise. I have updated question. Also added similar post yesterday: stackoverflow.com/questions/55375700/… If I add sync validation = Validators.required then error does not come.

– Harsimer
Mar 28 at 8:02






@SamVloeberghs thanks, yes my async validator returning promise. I have updated question. Also added similar post yesterday: stackoverflow.com/questions/55375700/… If I add sync validation = Validators.required then error does not come.

– Harsimer
Mar 28 at 8:02





1




1





your if should be inside the return new Promise. You have a potential case here that you are not return a promise.

– Sam Vloeberghs
Mar 28 at 8:24





your if should be inside the return new Promise. You have a potential case here that you are not return a promise.

– Sam Vloeberghs
Mar 28 at 8:24













@SamVloeberghs Ok thanks. Let me check and I will update you.

– Harsimer
Mar 28 at 8:41





@SamVloeberghs Ok thanks. Let me check and I will update you.

– Harsimer
Mar 28 at 8:41













@SamVloeberghs How can I return promise in that If conditione it is outside new promise?

– Harsimer
Mar 28 at 8:57





@SamVloeberghs How can I return promise in that If conditione it is outside new promise?

– Harsimer
Mar 28 at 8:57












0






active

oldest

votes










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);














draft saved

draft discarded
















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55391101%2fhow-can-we-set-sync-validation-null-when-adding-async-angular-validation%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes




Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.




















draft saved

draft discarded















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55391101%2fhow-can-we-set-sync-validation-null-when-adding-async-angular-validation%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현