{"id":19311989,"url":"https://github.com/weblineindia/reactjs-address-autosuggest","last_synced_at":"2025-04-22T15:31:35.993Z","repository":{"id":57347607,"uuid":"282228581","full_name":"weblineindia/ReactJS-Address-Autosuggest","owner":"weblineindia","description":"ReactJS based Address component which uses Google Maps Places API to autosuggest location address.","archived":false,"fork":false,"pushed_at":"2020-07-24T14:24:58.000Z","size":322,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-30T10:51:44.512Z","etag":null,"topics":["address-autocomplete","google-maps-api","google-maps-places","google-maps-places-api","location-autocomplete","react-address-autosuggest","react-components","react-demo","react-google-maps","react-libraries","reactjs","reactjs-address","reactjs-address-component","reactjs-components","reactjs-demo","reactjs-google-maps-api","reactjs-library","reusable-components"],"latest_commit_sha":null,"homepage":"https://www.weblineindia.com/software-development-resources.html","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/weblineindia.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-24T13:34:58.000Z","updated_at":"2023-08-10T20:17:23.000Z","dependencies_parsed_at":"2022-08-28T03:01:30.163Z","dependency_job_id":null,"html_url":"https://github.com/weblineindia/ReactJS-Address-Autosuggest","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weblineindia%2FReactJS-Address-Autosuggest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weblineindia%2FReactJS-Address-Autosuggest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weblineindia%2FReactJS-Address-Autosuggest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weblineindia%2FReactJS-Address-Autosuggest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/weblineindia","download_url":"https://codeload.github.com/weblineindia/ReactJS-Address-Autosuggest/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223900372,"owners_count":17222028,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["address-autocomplete","google-maps-api","google-maps-places","google-maps-places-api","location-autocomplete","react-address-autosuggest","react-components","react-demo","react-google-maps","react-libraries","reactjs","reactjs-address","reactjs-address-component","reactjs-components","reactjs-demo","reactjs-google-maps-api","reactjs-library","reusable-components"],"created_at":"2024-11-10T00:32:02.240Z","updated_at":"2024-11-10T00:32:18.294Z","avatar_url":"https://github.com/weblineindia.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ReactJS - Address Autosuggest\n\nAn ReactJS based Address component which uses Google Maps Places API to autosuggest location address.\n\n## Table of contents\n\n- [Browser Support](#browser-support)\n- [Demo](#demo)\n- [Installation](#installlation)\n- [Getting started](#getting-started)\n- [Usage](#usage)\n- [Available Props](#available-props)\n- [Methods](#methods)\n- [Want to Contribute?](#want-to-contribute)\n- [Collection of Components](#collection-of-components)\n- [Changelog](#changelog)\n- [Credits](#credits)\n- [License](#license)\n- [Keywords](#Keywords)\n\n## Browser Support\n\n| ![Chrome](https://raw.github.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png) | ![Firefox](https://raw.github.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png) | ![Safari](https://raw.github.com/alrra/browser-logos/master/src/safari/safari_48x48.png) | ![Edge](https://raw.github.com/alrra/browser-logos/master/src/edge/edge_48x48.png) | ![IE](https://raw.github.com/alrra/browser-logos/master/src/archive/internet-explorer_9-11/internet-explorer_9-11_48x48.png) |\n| ---------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |\n| 83.0 ✔                                                                                   | 77.0 ✔                                                                                      | 13.1.1 ✔                                                                                 | 83.0 ✔                                                                             | 11.9 ✔                                                                                                                       |\n\n## Demo\n\n[![](address.gif)](https://github.com/weblineindia/ReactJS-Address-Autosuggest/address.gif)\n\n## Installation\n\nThis component uses Google Maps Places API to get geo suggests for autocompletion, so you have to include the Google Maps Places API in the `\u003chead\u003e` of your HTML:\n\n```html\n\u003c!DOCTYPE html\u003e\n  \u003chtml\u003e\n  \u003chead\u003e\n    …\n    \u003cscript src=\"https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY_HERE\u0026libraries=places\"\u003e\u003c/script\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    …\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\nTo obtain API key please visit the [Google Developer Console](https://console.developers.google.com). The API's that you have to enable in your Google API Manager Dashboard are [Google Maps Geocoding API](https://developers.google.com/maps/documentation/geocoding/start), [Google Places API Web Service](https://developers.google.com/places/web-service/) and [Google Maps Javascript API] (https://developers.google.com/maps/documentation/javascript/).\n\n## Getting started\n\nInstall the npm package:\n\n``` bash\nnpm install react-weblineindia-address\n#OR\nyarn add react-weblineindia-address\n```\n\n## Usage\n\nUse the `\u003creact-weblineindia-address\u003e` component:\n\n```js\nimport React, { Component } from \"react\";\nimport Address from \"react-weblineindia-address\";\nclass Test extends Component {\n     constructor(props) {\n    super(props);\n    this.state = {\n         selectedAddressData: [],\n          errors: {},\n          address: [{ address: \"\" }],\n    }\n    /**\n   * This method is used to get country detail\n   */\n  handleSelectSuggest = (e, value, key, searchValue) =\u003e {\n    debugger;\n    let selectedAddress = this.state.selectedAddressData;\n    if (selectedAddress.length \u003e 0) {\n      selectedAddress[key].isSelectedAddress = true;\n    }\n    if (selectedAddress.length === 0) {\n      let selectedAddressfields = { isSelectedAddress: true };\n      selectedAddress.push(selectedAddressfields);\n    }\n    let data = this.state.address;\n    data[key].address = e;\n    data[key].search = \"\";\n\n    this.setState({ address: data, selectedAddressData: selectedAddress });\n    if (this.state.address.length \u003e 1) {\n      let results = [];\n      for (let i = 0; i \u003c this.state.address.length - 1; i++) {\n        for (let j = i + 1; j \u003c this.state.address.length; j++) {\n          if (\n            this.state.address[i].address.toLowerCase() ===\n            this.state.address[j].address.toLowerCase()\n          ) {\n            if (this.state.address[i].address.trim().length \u003e 0) {\n              results.push(this.state.address[i]);\n            }\n          }\n        }\n      }\n      let errors = this.state.errors;\n\n      if (results.length \u003e 0) {\n        errors[\"sameAddressError\"] = \"Do not enter same Address\";\n      } else {\n        errors[\"sameAddressError\"] = \"\";\n      }\n      this.setState({ errors: errors });\n    }\n  };\n\n   /**\n   * This method used to new field\n   * @param e\n   * @param value\n   */\n  onPlusClick(e, value, i) {\n    let selectedAddressData = this.state.selectedAddressData;\n    let selectedAddressD = { isSelectedAddress: false };\n    selectedAddressData.push(selectedAddressD);\n    this.state.address.push({\n      address: \"\",\n    });\n    this.setState({ selectedAddressData });\n  }\n   /**\n   * This Method is used for Blur input\n   * @param {*} event \n   */\n  onBlurInput(event) {\n    event.target.placeholder = \"Address\";\n  }\n  /**\n   * This method is used for focus input\n   * @param {*} event \n   */\n  onFocusInput(event) {\n    debugger;\n    event.target.placeholder = \"\";\n  }\n   /**\n   * This method is used to get address field value\n   * @param e\n   * @param value\n   * @param key\n   * @param searchValue\n   */\n  onHandleAddressChange(e, value, key, searchValue) {\n    let data = this.state.address;\n    data[key].address = e;\n    data[key].search = e;\n\n    let selectedAddressData = this.state.selectedAddressData;\n    if (e === \"\") {\n      if (selectedAddressData.length \u003e 0) {\n        selectedAddressData[key].isSelectedAddress = false;\n      }\n    }\n    this.setState({ address: data });\n  }\n    render(){\n        return(\n           \u003cdiv\u003e\n        {this.state.address \u0026\u0026\n          this.state.address.map((cdiv, i) =\u003e {\n            return (\n              \u003cdiv id=\"address\"\u003e\n                \u003cPlaceAddress\n                  index={i}\n                  tabIndex={0}\n                  streetPlaceholder=\"Street Number\"\n                  value={cdiv.address}\n                  onChange={(e) =\u003e {\n                    this.onHandleAddressChange(e, \"address\", i, \"search\");\n                  }}\n                  placeholder=\"Address\"\n                  className={\n                    (\n                      cdiv.address === undefined\n                        ? cdiv\n                        : cdiv.address.length \u003e 0\n                    )\n                      ? \"location-search-input form-control textvisible\"\n                      : \"location-search-input form-control\"\n                  }\n                  id={\"search\" + i + \"Txt\"}\n                  elmkey=\"address\"\n                  onFocus={(e) =\u003e {\n                    this.onFocusInput.bind(this);\n                  }}\n                  onBlur={(e) =\u003e {\n                    this.onBlurInput.bind(this);\n                  }}\n                  country=\"in\"\n                  onSelect={(e) =\u003e {\n                    this.handleSelectSuggest(e, \"address\", i, \"search\");\n                  }}\n                /\u003e\n                \u003cReact.Fragment className=\"add-remove\"\u003e\n                  \u003cReact.Fragment \u003e\n                    \u003cdiv className=\"add-minus\"\u003e\n                      \u003ci className=\"fa fa-minus\" aria-hidden=\"true\"\u003e\u003c/i\u003e\n                    \u003c/div\u003e\n                  \u003c/React.Fragment\u003e\n                  {this.state.address.length - 1 === i ? (\n                    \u003cdiv\u003e\n                      \u003ci\n                        className=\"fa fa-plus\"\n                        aria-hidden=\"true\"\n                        onClick={this.onPlusClick.bind(this)}\n                      \u003e\u003c/i\u003e\n                    \u003c/div\u003e\n                  ) : (\n                    \"\"\n                  )}\n                \u003c/React.Fragment\u003e\n                {this.state.errors[\"sameAddressError\"] ? (\n                  \u003cp\u003e\n                    \u003cspan className=\"error-msg\"\u003e\n                      {this.state.errors[\"sameAddressError\"]}\n                    \u003c/span\u003e\n                  \u003c/p\u003e\n                ) : (\n                  \"\"\n                )}\n              \u003c/div\u003e\n            );\n          })}\n      \u003c/div\u003e\n        )\n    }\n}\nexport default Test;\n```\n\n## Available Props\n\n| Prop | Type | default | Description |\n| --- | --- | --- | --- |\n| id | String |   |ID for the input container |\n| name | String |   |Name of the component |\n| value | Array |  address: [ {address: \"\", geolocation: { x: 0, y: 0 }, country: \"\",locality: \"\",postalcode: \"\", state: \"\",province: \"\",fulladdress: \"\", streetaddress: \"\",isDuplicate: false}]  | Value of the component |\n| classname | String |   |  Class to the input container |\n| streetPlaceholder | String |   | The input field will get this placeholder text |\n| isShowStreetField | Boolean | false  | hide /show street number field |\n| placeholder | String |   | The input field will get this placeholder text ||\n| country | `Array` | null  |  Option to restrict the autocomplete search to a particular country. Countries must be passed as a two-character, ISO 3166-1 Alpha-2 compatible country code (i.e. \"br\", \"sg\", \"fr\"). You can provide a single one, or an array of up to 5 country code strings. |\n| hide | Boolean | false  | Hide component  |\n| disabled | Boolean | false  | Disable component  |\n| tabindex | Number |   | Tab index of the component  |\n| index | Number |   | Add key of the component  |\n| maxlength | Number |   | The input maxlength  |\n\n## Methods\n\n| Name | Description |\n| --- | --- |\n| focus | Gets triggered when the autocomplete input field receives focus. |\n| blur | Gets triggered when the autocomplete input field loses focus. |\n| inputChange | Gets triggered every time autocomplete input got changed. |\n| onMultipleAddressAdd | Gets triggered every time when add plus icon  |\n| change | Gets triggered when the autocomplete results got changed. |\n| keypress | Gets triggered when a key gets pressed. |\n| error | Gets triggered when an error is encountered. |\n| placechanged | Gets triggered when the address data got obtained. This data is available on the returned objects: `street_number`,`route`, `locality`, `administrative_area_level_1`, `country`, `postal_code`, `latitude`, `longitude`. `place` - [PlaceResult object](https://developers.google.com/maps/documentation/javascript/reference#PlaceResult) is available as second parameter.`id` a String representing the ID of the autocomplete that triggered the event. |\n\n## Want to Contribute?\n\n- Created something awesome, made this code better, added some functionality, or whatever (this is the hardest part).\n- [Fork it](http://help.github.com/forking/).\n- Create new branch to contribute your changes.\n- Commit all your changes to your branch.\n- Submit a [pull request](http://help.github.com/pull-requests/).\n\n-----\n\n## Collection of Components\nWe have built many other components and free resources for software development in various programming languages. Kindly click here to view our [Free Resources for Software Development](https://www.weblineindia.com/software-development-resources.html )\n\n------\n\n## Changelog\n\nDetailed changes for each release are documented in [CHANGELOG.md](./CHANGELOG.md).\n\n## Credits\n\nreact-weblineindia-address is inspired by [React Places Autocomplete](https://www.npmjs.com/package/react-places-autocomplete).\n\n## License\n\n[MIT](LICENSE)\n\n[mit]: https://github.com/weblineindia/ReactJS-Address-Autosuggest/blob/master/LICENSE\n\n## Keywords\n\nreact-weblineindia-address, react-address, reactjs-address, react-autocomplete, react-google-place, react-google-maps-places, google-maps-places-api\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweblineindia%2Freactjs-address-autosuggest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fweblineindia%2Freactjs-address-autosuggest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweblineindia%2Freactjs-address-autosuggest/lists"}