import React, { Component } from 'react'; import { HashRouter, Route, NavLink } from 'react-router-dom'; import classNames from 'classnames'; import Cookies from 'universal-cookie'; import fetch from 'isomorphic-fetch'; import JsonPointer from 'json-pointer'; import PropertySet from './components/PropertySet'; import Property from './components/Property'; import bean from './testJson.json'; import testOuter from './testOuter.json'; import validationTest from './validationTest.json'; import layout1 from './layout1.json'; import layout2 from './layout2.json'; import devJson from './devJson.json'; import 'react-datetime/css/react-datetime.css'; import "./app.css"; import "./propertySet.css"; class AllPropertyTypes extends Component { constructor(props) { super(props); this.state = { bean: bean, values: bean.values }; this.handleFieldChange = this.handleFieldChange.bind(this); this.reloadOnChange = this.reloadOnChange.bind(this); this.handleSubmit = this.handleSubmit.bind(this); this.handleJsonChange = this.handleJsonChange.bind(this); } componentDidMount(){ const cookies = new Cookies(); this.setState({ cookies: cookies, horizontal: cookies.get('horizontal', { path: '/' }) === 'true', wasValidated: cookies.get('wasValidated', { path: '/' }) === 'true', readOnly: cookies.get('readOnly', { path: '/' }) === 'true', bsSize: cookies.get('bsSize', { path: '/' }), }); } handleSubmit(event) { console.log('submit:', this.state.values); event.preventDefault(); } handleJsonChange(event) { const bean = JSON.parse(event.target.value); this.setState({bean: bean, values : bean.values}); } handleFieldChange(path, value) { console.log("onChange: ", path, value); const nextValues = Object.assign({}, this.state.values); JsonPointer.set(nextValues, path, value); this.setState({values: nextValues}); } reloadOnChange(path, value) { console.log("reloadOnChange: ", path, value); if (value !== undefined) { const nextValues = Object.assign({}, this.state.values); JsonPointer.set(nextValues, path, value); this.setState({values: nextValues}); } } getBean(){ if(this.state.readOnly){ let beanJson = JSON.stringify(this.state.bean); const readOnlyBean = JSON.parse(beanJson); for(let item in readOnlyBean.meta) { readOnlyBean.meta[item]['readOnly'] = true; } return readOnlyBean; } return this.state.bean; } getForm(){ const selectLoadOptions = (params, callback) => { const {input, entity, query} = params; setTimeout(() => { const options = [ { value: input, label: input }, ]; console.log('selectLoadOptions for ' + JSON.stringify(params) + ' - ' + JSON.stringify(options)); callback(null, { options: options, // CAREFUL! Only set this to true when there are no more options, // or more specific queries will not be sent to the server. complete: false }); }, 500); }; const selectLoadGithubUsers = (params, callback) => { const {input, entity, query} = params; fetch('https://api.github.com/search/users?q=' + (input || 'a')) .then(response => { return response.json().then(json => { const options = []; json.items.forEach(x => { options.push({value: x.id, label: x.login}) }); callback(null, { options: options, // CAREFUL! Only set this to true when there are no more options, // or more specific queries will not be sent to the server. complete: false }); }); }); }; const selectLoadBe5Query = (params, callback) => { const {input, entity, query} = params; fetch('http://localhost:8200/api/table?_en_=customers&_qn_=***%20Selection%20view%20***&_params_=' + '%7B%22asyncValue%22%3A%22' + input + '%22%7D&_ts_=1556103737910') .then(response => { return response.json().then(json => { const options = []; json.data.attributes.rows.forEach(x => { options.push({value: x.cells[0].content, label: x.cells[1].content}) }); callback(null, { options: options, // CAREFUL! Only set this to true when there are no more options, // or more specific queries will not be sent to the server. complete: false }); }); }); }; return (
{this.getSubmitBtn()} ) } getSubmitBtn(className){ return ( ) } //btn-sm render() { return (
onChange in the console [Chrome F12]
{this.getForm()}