const phone = document.getElementById('phone');
const phoneFormat = function(e) {
let content = e.target.value;
if(!content) return;
content = Array.from(content).filter(ltr => ltr.charCodeAt(0) > 47 && ltr.charCodeAt(0) < 58);
switch(content[0]) {
case "8":
content[0] = "7";
break;
case "9":
content.unshift("7");
break;
default:
break;
}
let [countryCode, operatorCode, number3, number21, number22] = [
content[0],
content.slice(1,4).join(''),
content.slice(4,7).join(''),
content.slice(7,9).join(''),
content.slice(9,11).join(''),
]
e.target.value = countryCode.length ? `+${countryCode}` : '';
if(operatorCode.length) e.target.value += `(${operatorCode}`;
if(number3.length) e.target.value += `)${number3}`;
if(number21.length) e.target.value += `-${number21}`;
if(number22.length) e.target.value += `-${number22}`;
}
phone.oninput = (e) => phoneFormat(e);
<Parent>
<Child1><a data-title="на старт" /></Child1>
<Child2></*что-то для изменения, например param*/></Child2>
</Parent>
class Parent extends React.Component {
state = {
naStart: false
}
handleClick = (event) => {
if (event.target.dataTitle === "на старт") {
this.setState({naStart: true})
}
}
render() {
return (
<div>
<Child1 onClick={this.handleClick} />
<Child2 param={this.state.naStart} />
</div>
)
}
}
this.state = {
isAlertVisible: false
}
// ...
<Alert isVisible={this.state.isAlertVisible} />
handleClick = event => {
// ...
this.setState({isAlertVisible: true}, () => {
setTimeout(
() => {this.setState({isAlertVisible: false})},
3000
)
})
}
<label><input onClick={this.changeTitle} type='checkbox' value={!this.state.clicked ? 'lf' : 'ytn'} />{!this.state.clicked ? 'lf' : 'ytn'} </label>
constructor(props) {
super(props);
this.onFinish = this.onFinish.bind(this);
}
onFinish(values) {
console.log('Received values of form: ', values);
let login = values.login;
let password = values.password;
this.props.onSignIn(login, password)
}
const store = createStore(rootReducer)
export default connect(mapStateToProps, mapDispatchToProps)(App)