mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2025-01-30 22:45:32 +01:00
Also validate on constructor
This commit is contained in:
parent
a51442921a
commit
f0371b41b1
1 changed files with 36 additions and 26 deletions
|
@ -3,22 +3,8 @@ import PropTypes from 'prop-types'
|
||||||
import StringInput from './StringInput'
|
import StringInput from './StringInput'
|
||||||
import SmallError from '../util/SmallError'
|
import SmallError from '../util/SmallError'
|
||||||
|
|
||||||
class UrlInput extends React.Component {
|
|
||||||
static propTypes = {
|
|
||||||
"data-wd-key": PropTypes.string,
|
|
||||||
value: PropTypes.string,
|
|
||||||
style: PropTypes.object,
|
|
||||||
default: PropTypes.string,
|
|
||||||
onChange: PropTypes.func,
|
|
||||||
multi: PropTypes.bool,
|
|
||||||
required: PropTypes.bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
state = {
|
function validate (url) {
|
||||||
error: null,
|
|
||||||
}
|
|
||||||
|
|
||||||
onInput = (url) => {
|
|
||||||
let error;
|
let error;
|
||||||
const getProtocol = (url) => {
|
const getProtocol = (url) => {
|
||||||
try {
|
try {
|
||||||
|
@ -42,7 +28,31 @@ class UrlInput extends React.Component {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setState({error});
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
class UrlInput extends React.Component {
|
||||||
|
static propTypes = {
|
||||||
|
"data-wd-key": PropTypes.string,
|
||||||
|
value: PropTypes.string,
|
||||||
|
style: PropTypes.object,
|
||||||
|
default: PropTypes.string,
|
||||||
|
onChange: PropTypes.func,
|
||||||
|
multi: PropTypes.bool,
|
||||||
|
required: PropTypes.bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor (props) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
error: validate(props.value)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
onInput = (url) => {
|
||||||
|
this.setState({
|
||||||
|
error: validate(url)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
|
|
Loading…
Reference in a new issue