Skip to content

Commit 9faec63

Browse files
ntthitrinhkhangon
andauthored
feature-8878: Can't read errors related to unfilled fields in the form (#9006)
Co-authored-by: Khang On - TMA <[email protected]>
1 parent e94221c commit 9faec63

File tree

1 file changed

+73
-128
lines changed

1 file changed

+73
-128
lines changed

app/components/forms/orders/order-form.js

Lines changed: 73 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -281,17 +281,6 @@ export default Component.extend(FormMixin, {
281281
]
282282
};
283283

284-
const websiteValidation = {
285-
optional : true,
286-
rules : [
287-
{
288-
type : 'regExp',
289-
value : compulsoryProtocolValidUrlPattern,
290-
prompt : this.l10n.t('Please enter a valid URL.')
291-
}
292-
]
293-
};
294-
295284
const websiteRequiredValidation = {
296285
rules: [
297286
{
@@ -306,16 +295,6 @@ export default Component.extend(FormMixin, {
306295
]
307296
};
308297

309-
const blogValidation = {
310-
optional : true,
311-
rules : [
312-
{
313-
type : 'regExp',
314-
value : compulsoryProtocolValidUrlPattern,
315-
prompt : this.l10n.t('Please enter a valid URL.')
316-
}
317-
]
318-
};
319298

320299
const blogRequiredValidation = {
321300
rules: [
@@ -331,16 +310,6 @@ export default Component.extend(FormMixin, {
331310
]
332311
};
333312

334-
const twitterValidation = {
335-
optional : true,
336-
rules : [
337-
{
338-
type : 'regExp',
339-
value : validTwitterProfileUrlPattern,
340-
prompt : this.l10n.t('Please enter a valid Twitter profile URL.')
341-
}
342-
]
343-
};
344313

345314
const twitterRequiredValidation = {
346315
rules: [
@@ -356,16 +325,6 @@ export default Component.extend(FormMixin, {
356325
]
357326
};
358327

359-
const facebookValidation = {
360-
optional : true,
361-
rules : [
362-
{
363-
type : 'regExp',
364-
value : validFacebookProfileUrlPattern,
365-
prompt : this.l10n.t('Please enter a valid Facebook account URL.')
366-
}
367-
]
368-
};
369328

370329
const facebookRequiredValidation = {
371330
rules: [
@@ -381,17 +340,6 @@ export default Component.extend(FormMixin, {
381340
]
382341
};
383342

384-
const githubValidation = {
385-
optional : true,
386-
rules : [
387-
{
388-
type : 'regExp',
389-
value : validGithubProfileUrlPattern,
390-
prompt : this.l10n.t('Please enter a valid GitHub profile URL.')
391-
}
392-
]
393-
};
394-
395343
const githubRequiredValidation = {
396344
rules: [
397345
{
@@ -406,17 +354,6 @@ export default Component.extend(FormMixin, {
406354
]
407355
};
408356

409-
const instagramValidation = {
410-
optional : true,
411-
rules : [
412-
{
413-
type : 'regExp',
414-
value : validInstagramProfileUrlPattern,
415-
prompt : this.l10n.t('Please enter a valid Instagram account URL.')
416-
}
417-
]
418-
};
419-
420357
const instagramRequiredValidation = {
421358
rules: [
422359
{
@@ -431,16 +368,6 @@ export default Component.extend(FormMixin, {
431368
]
432369
};
433370

434-
const linkedinValidation = {
435-
optional : true,
436-
rules : [
437-
{
438-
type : 'regExp',
439-
value : validLinkedinProfileUrlPattern,
440-
prompt : this.l10n.t('Please enter a valid Linkedin account URL.')
441-
}
442-
]
443-
};
444371

445372
const linkedinRequiredValidation = {
446373
rules: [
@@ -459,7 +386,7 @@ export default Component.extend(FormMixin, {
459386
const isConsentFormFieldValidation = {
460387
rules: [
461388
{
462-
type : 'empty',
389+
type : 'checkbox',
463390
prompt : this.l10n.t('Please enter Code of conduct consent.')
464391
}
465392
]
@@ -560,63 +487,81 @@ export default Component.extend(FormMixin, {
560487
}
561488
}
562489
};
563-
this.holders.forEach((value, index) => {
564-
validationRules.fields[`firstname_required_${index}`] = firstNameValidation;
565-
validationRules.fields[`lastname_required_${index}`] = lastNameValidation;
566-
validationRules.fields[`email_required_${index}`] = emailValidation;
567-
validationRules.fields[`gender_required_${ index}`] = genderValidation;
568-
validationRules.fields[`ageGroup_required_${ index}`] = ageGroupValidation;
569-
validationRules.fields[`address_required_${ index}`] = addressValidation;
570-
validationRules.fields[`acceptReceiveEmails_required_${ index}`] = acceptReceiveEmailsValidation;
571-
validationRules.fields[`acceptVideoRecording_required_${ index}`] = acceptVideoRecordingValidation;
572-
validationRules.fields[`acceptShareDetails_required_${ index}`] = acceptShareDetailsValidation;
573-
validationRules.fields[`city_required_${ index}`] = cityValidation;
574-
validationRules.fields[`state_required_${ index}`] = stateValidation;
575-
validationRules.fields[`country_required_${ index}`] = countryValidation;
576-
validationRules.fields[`jobTitle_required_${ index}`] = jobTitleValidation;
577-
validationRules.fields[`phone_required_${ index}`] = phoneValidation;
578-
validationRules.fields[`taxBusinessInfo_required_${ index}`] = taxBusinessInfoValidation;
579-
validationRules.fields[`billingAddress_required_${ index}`] = billingAddressValidation;
580-
validationRules.fields[`homeAddress_required_${ index}`] = homeAddressValidation;
581-
validationRules.fields[`homeWiki_required_${ index}`] = homeWikiValidation;
582-
validationRules.fields[`wikiScholarship_required_${ index}`] = wikiScholarshipValidation;
583-
validationRules.fields[`shippingAddress_required_${ index}`] = shippingAddressValidation;
584-
validationRules.fields[`company_required_${ index}`] = companyValidation;
585-
validationRules.fields[`workAddress_required_${ index}`] = workAddressValidation;
586-
validationRules.fields[`workPhone_required_${ index}`] = workPhoneValidation;
587-
validationRules.fields[`website_${ index}`] = websiteValidation;
588-
validationRules.fields[`website_required_${ index}`] = websiteRequiredValidation;
589-
validationRules.fields[`blog_${ index}`] = blogValidation;
590-
validationRules.fields[`blog_required_${ index}`] = blogRequiredValidation;
591-
validationRules.fields[`twitter_${ index}`] = twitterValidation;
592-
validationRules.fields[`twitter_required_${ index}`] = twitterRequiredValidation;
593-
validationRules.fields[`facebook_${ index}`] = facebookValidation;
594-
validationRules.fields[`facebook_required_${ index}`] = facebookRequiredValidation;
595-
validationRules.fields[`github_${ index}`] = githubValidation;
596-
validationRules.fields[`github_required_${ index}`] = githubRequiredValidation;
597-
validationRules.fields[`instagram_${ index}`] = instagramValidation;
598-
validationRules.fields[`instagram_required_${ index}`] = instagramRequiredValidation;
599-
validationRules.fields[`linkedin_${ index}`] = linkedinValidation;
600-
validationRules.fields[`linkedin_required_${ index}`] = linkedinRequiredValidation;
601-
validationRules.fields[`native_language_required_${ index}`] = nativeLanguageValidation;
602-
validationRules.fields[`fluent_language_required_${ index}`] = fluentLanguageValidation;
603-
validationRules.fields[`is_consent_form_field_required_${ index}`] = isConsentFormFieldValidation;
604-
validationRules.fields[`is_consent_of_refund_policy_required_${ index}`] = isConsentOfRefundPolicyValidation;
605-
this.allFields.attendee.filter(field => field.isComplex && field.isRequired).forEach(field => {
606-
validationRules.fields[`${field.fieldIdentifier}_required_${index}`] = {
607-
rules: [
608-
{
609-
type : 'empty',
610-
prompt : this.l10n.t('Please enter {{field}}.', { field: field.name })
611-
}
612-
]
613-
};
614-
});
615-
490+
const validationMap = {
491+
firstname : firstNameValidation,
492+
lastname : lastNameValidation,
493+
email : emailValidation,
494+
gender : genderValidation,
495+
ageGroups : ageGroupValidation,
496+
address : addressValidation,
497+
acceptReceiveEmails : acceptReceiveEmailsValidation,
498+
acceptVideoRecording : acceptVideoRecordingValidation,
499+
acceptShareDetails : acceptShareDetailsValidation,
500+
city : cityValidation,
501+
state : stateValidation,
502+
country : countryValidation,
503+
jobTitle : jobTitleValidation,
504+
phone : phoneValidation,
505+
taxBusinessInfo : taxBusinessInfoValidation,
506+
billingAddress : billingAddressValidation,
507+
homeAddress : homeAddressValidation,
508+
homeWiki : homeWikiValidation,
509+
wikiScholarship : wikiScholarshipValidation,
510+
shippingAddress : shippingAddressValidation,
511+
company : companyValidation,
512+
workAddress : workAddressValidation,
513+
workPhone : workPhoneValidation,
514+
website : websiteRequiredValidation,
515+
blog : blogRequiredValidation,
516+
twitter : twitterRequiredValidation,
517+
facebook : facebookRequiredValidation,
518+
github : githubRequiredValidation,
519+
instagram : instagramRequiredValidation,
520+
linkedin : linkedinRequiredValidation,
521+
native_language : nativeLanguageValidation,
522+
fluent_language : fluentLanguageValidation,
523+
is_consent_form_field : isConsentFormFieldValidation,
524+
is_consent_of_refund_policy : isConsentOfRefundPolicyValidation
525+
526+
};
527+
this.allFields.attendee.forEach((field, index) => {
528+
const { fieldIdentifier } = field;
529+
const validationRuleKey = `${fieldIdentifier}_required_${index}`;
530+
if (validationMap[fieldIdentifier]) {
531+
validationRules.fields[validationRuleKey] = validationMap[fieldIdentifier];
532+
} else {
533+
if (field.type === 'checkbox') {
534+
validationRules.fields[`${field.fieldIdentifier}_required_${index}`] = {
535+
rules: [
536+
{
537+
type : 'checkbox',
538+
prompt : this.l10n.t('Please select your {{field}}.', { field: field.name })
539+
}
540+
]
541+
};
542+
} else if (field.type === 'boolean') {
543+
validationRules.fields[`${field.fieldIdentifier}_required_${index}`] = {
544+
rules: [
545+
{
546+
type : 'checked',
547+
prompt : this.l10n.t('Please choosen your {{field}}.', { field: field.name })
548+
}
549+
]
550+
};
551+
} else {
552+
validationRules.fields[`${field.fieldIdentifier}_required_${index}`] = {
553+
rules: [
554+
{
555+
type : 'empty',
556+
prompt : this.l10n.t('Please enter your {{field}}.', { field: field.name })
557+
}
558+
]
559+
};
560+
}
561+
}
616562
});
617563
return validationRules;
618564
},
619-
620565
allFields: computed('fields', function() {
621566
const requiredFixed = this.fields.toArray()?.filter(field => field.isFixed);
622567
const current_locale = this.cookies.read('current_locale');

0 commit comments

Comments
 (0)