Skip to content

Commit

Permalink
IBX-6136: Changed value validation logic for anchor (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszdebinski authored Jul 19, 2023
1 parent e89026a commit a2d97eb
Showing 1 changed file with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ export default class EzBtnAnchorEdit extends Component {
componentDidMount() {
const block = this.findBlock();
const value = block.getId();
const isValueUnique = this.isValueUnique(value);
const isValueValid = this.isValueValid(value);

this.setState(() => ({ value, isValueUnique, isValueValid }));
this.checkValueIsValidAndUnique(value);
}

static get key() {
Expand Down Expand Up @@ -74,10 +72,8 @@ export default class EzBtnAnchorEdit extends Component {

updateValue({ nativeEvent }) {
const value = nativeEvent.target.value;
const isValueUnique = this.isValueUnique(value);
const isValueValid = this.isValueValid(value);

this.setState(() => ({ value, isValueUnique, isValueValid }));
this.checkValueIsValidAndUnique(value);
}

isValueUnique(value) {
Expand Down Expand Up @@ -190,6 +186,20 @@ export default class EzBtnAnchorEdit extends Component {
return <em className="ez-ae-anchor-edit__error">{errorMessage}</em>;
}

checkValueIsValidAndUnique(value) {
const isValueValid = this.isValueValid(value);

if (!isValueValid) {
this.setState(() => ({ value, isValueValid }));

return;
}

const isValueUnique = this.isValueUnique(value);

this.setState(() => ({ value, isValueUnique, isValueValid }));
}

/**
* Lifecycle. Renders the UI of the button.
*
Expand Down

0 comments on commit a2d97eb

Please sign in to comment.