Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. import { Card, Col, Divider, Form, Input, Row } from "antd";
  2. import { LocationSearchInput } from "./location-search";
  3. import { geocodeByAddress, getLatLng } from "react-places-autocomplete";
  4. import { FormComponentProps } from "antd/lib/form/Form";
  5.  
  6. type Props = {} & FormComponentProps;
  7.  
  8. type State = {
  9. address: string;
  10. };
  11.  
  12. class SomeClass extends React.Component<Props, State> {
  13. state: State = {
  14. address: ""
  15. };
  16.  
  17. clearAddress = (): void => {
  18. // Clear with this.props.form.setFieldsValue();
  19. };
  20.  
  21. handleAddressChange = (address: string): void => {
  22. // Do something with address
  23. };
  24.  
  25. handleAddressSelect = (address: string, placeID: string): void => {
  26. geocodeByAddress(address)
  27. .then(async (results: google.maps.GeocoderResult[]) => {
  28. // Do something with results[0]
  29. return getLatLng(results[0]);
  30. })
  31. .then((latLng: google.maps.LatLngLiteral) => {
  32. // Do something with latLng
  33. })
  34. .catch((error: any) => {
  35. console.error("Error", error);
  36. });
  37. };
  38.  
  39. componentDidMount(): void {
  40. this.props.form.setFieldsValue({
  41. addressInput: ""
  42. });
  43. }
  44.  
  45. render() {
  46. return (
  47. <Form>
  48. <Row>
  49. <Col>
  50. <FormItem>
  51. <span>Address</span>
  52. {getFieldDecorator("addressInput", {
  53. initialValue: "",
  54. rules: [{ required: false }]
  55. })(
  56. <LocationSearchInput
  57. address={this.state.address}
  58. clearAddress={this.clearAddress}
  59. onChange={this.handleAddressChange}
  60. onAddressSelect={this.handleAddressSelect}
  61. />
  62. )}
  63. </FormItem>
  64. </Col>
  65. </Row>
  66. </Form>
  67. );
  68. }
  69. }
  70.  
  71. export const WrappedSomeClass = Form.create()(SomeClass);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement