-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AD-224 Implement Robust Form Validation for Delivery and Billing Addr…
…ess Forms
- Loading branch information
Showing
21 changed files
with
214 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...heckoutaddonapi/acceleratoraddon/web/src/com/adyen/commerce/util/FieldValidationUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.adyen.commerce.util; | ||
|
||
import org.springframework.validation.Errors; | ||
import org.springframework.validation.FieldError; | ||
|
||
import java.util.List; | ||
|
||
public class FieldValidationUtil { | ||
public static List<String> getFieldCodesFromValidation(Errors errors) { | ||
return errors.getFieldErrors().stream().map(FieldError::getField).toList(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 25 additions & 9 deletions
34
...on/web/webroot/_ui/responsive/common/js/adyen-checkout/src/components/common/ScrollTo.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,38 @@ | ||
import React, {RefObject} from "react"; | ||
import React from "react"; | ||
|
||
|
||
export class ScrollHere extends React.Component<{}, null> { | ||
private readonly ref: RefObject<any> = undefined; | ||
private scrollHereClass: string = "adyen-scroll-here"; | ||
|
||
constructor(props: {}) { | ||
super(props); | ||
this.ref = React.createRef(); | ||
private scrollToFirstInstance() { | ||
let elementsByClassName = document.getElementsByClassName(this.scrollHereClass); | ||
if (elementsByClassName && elementsByClassName.length > 0) { | ||
let newTop = this.getNewTopPosition(elementsByClassName); | ||
newTop = newTop - 10; | ||
window.scrollBy({top: newTop, behavior: 'smooth'}); | ||
} | ||
} | ||
|
||
private getNewTopPosition(elementsByClassName: HTMLCollectionOf<Element>) { | ||
let newTop: number = undefined; | ||
|
||
for (let i = 0; i < elementsByClassName.length; i++) { | ||
let elementTop = elementsByClassName.item(i).getBoundingClientRect().top; | ||
if (i === 0) { | ||
newTop = elementTop; | ||
} | ||
if (elementTop < newTop) { | ||
newTop = elementTop; | ||
} | ||
} | ||
return newTop; | ||
} | ||
|
||
componentDidMount() { | ||
if (this.ref) { | ||
this.ref.current.scrollIntoView({behavior: 'smooth'}) | ||
} | ||
this.scrollToFirstInstance() | ||
} | ||
|
||
render() { | ||
return <div ref={this.ref}></div> | ||
return <div className={this.scrollHereClass}></div> | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...eb/webroot/_ui/responsive/common/js/adyen-checkout/src/components/controls/FieldGroup.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React from "react"; | ||
import {translationsStore} from "../../store/translationsStore"; | ||
|
||
interface ComponentProps { | ||
hasError: boolean | ||
errorMessageCode: string | ||
} | ||
|
||
type Props = React.PropsWithChildren & ComponentProps | ||
|
||
export class FieldGroup extends React.Component<Props, null> { | ||
|
||
render() { | ||
if (this.props.hasError) { | ||
return ( | ||
<div className={"form-group has-error"}> | ||
{this.props.children} | ||
<div className="help-block"> | ||
<span>{translationsStore.get(this.props.errorMessageCode)}</span> | ||
</div> | ||
</div> | ||
) | ||
} else { | ||
return ( | ||
<div className={"form-group"}> | ||
{this.props.children} | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.