diff --git a/CHANGELOG.md b/CHANGELOG.md index 85ec82f..36971c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,35 +4,38 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## 0.0.21 - 2020.07.31 +### Fixes + - Fixed Issue #58 - https://github.com/newism/craft3-fields/issues/58 ## 0.0.20 - 2020.07.23 ### Fixes - Fixed map loading when google hasn't loaded - + ## 0.0.19 - 2020.07.23 ### Updated - Added map + marker to Address field - + ## 0.0.18 - 2020.07.22 ### Updated - Google API Key Setting can now be set as an `$_ENV` variables - Code clean up - + ## 0.0.17 - 2020.07.22 ### Added - New setting to hide Address Place Data ### Fixes - Disabling AutoComplete breaks things! #43 - + ## 0.0.16 - 2020.07.21 ### Fixes - Fixes Show Map Url field option - Fixes Person Name field spacing - Added flex wrap and margins - + ## 0.0.15 - 2020.05.19 ### Fixes - Fixes Neo / Matrix integration - + ## 0.0.14 - 2019.01.15 ### Fixes - Fixes #30: Default Country Code doesn't do anything. @@ -46,7 +49,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p - Address uses a formatted string for search keywords - Embed uses the embed title for search keywords ### Fixed -- Fixes #39 Adresse cannot contain emoji - Address and Embed now use `StringHelper::encodeMb4` to serialize their DB value +- Fixes #39 Adresse cannot contain emoji - Address and Embed now use `StringHelper::encodeMb4` to serialize their DB value ## 0.0.11 - 2018.08.21 ### Added @@ -59,15 +62,15 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ## 0.0.10 - 2018.1.03 ### Fixed - Fixes #22 Encode all emoticons in shortcodes using LitEmoji -- Craft 3 RC-13 compatibility +- Craft 3 RC-13 compatibility ## 0.0.8 - 2018.6.02 ### Fixed -- Fixes #18 Telephone field causes a PHP error when entry is saved +- Fixes #18 Telephone field causes a PHP error when entry is saved ## 0.0.7 - 2017.12.08 ### Fixed -- Fixes #15 Cannot read property 'serialize' of undefined - Address.js:88 +- Fixes #15 Cannot read property 'serialize' of undefined - Address.js:88 ## 0.0.6 - 2017.12.04 ### Changed diff --git a/composer.json b/composer.json index 353d389..74b9499 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "newism/craft3-fields", "description": "Address, telephone and email fields for CraftCMS 3.x", "type": "craft-plugin", - "version": "0.0.20", + "version": "0.0.21", "keywords": [ "craft", "cms", diff --git a/src/assetbundles/addressfield/dist/js/Address.js b/src/assetbundles/addressfield/dist/js/Address.js index e0fb777..4b732bf 100644 --- a/src/assetbundles/addressfield/dist/js/Address.js +++ b/src/assetbundles/addressfield/dist/js/Address.js @@ -33,7 +33,7 @@ Plugin.prototype = { getElement: function (element) { - return this.$element.find('#' + this.options.namespace + '-' + element); + return this.$element.find('#' + this.options.namespacedId + '-' + element); }, init: function (id) { @@ -149,17 +149,18 @@ this.$spinner.removeClass('hidden'); jqXHR = Craft.postActionRequest( - 'entries/switch-entry-type', - Craft.cp.$primaryForm.serialize(), + 'nsm-fields/address/refresh-country', + { + 'CRAFT_CSRF_TOKEN': Craft.cp.$primaryForm.find('[name="CRAFT_CSRF_TOKEN"]').val(), + 'countryCode': this.currentCountryCode, + 'namespace': this.options.namespace, + }, $.proxy(function (response, textStatus) { - var newHtml; this.$spinner.addClass('hidden'); if (textStatus === 'success') { - newHtml = $(response.fieldsHtml).find('#' + this.options.namespace + '-field .nsmFields-address-addressFieldsContainer'); - newHtml.toggle(!!this.$countryCodeInput.val()); + var newHtml = $(response.html).find('.nsmFields-address-addressFieldsContainer'); this.$addressFieldsContainer.replaceWith(newHtml); this.$addressFieldsContainer = newHtml; - Craft.initUiElements(this.$addressFieldsContainer); } }, this)); diff --git a/src/controllers/AddressController.php b/src/controllers/AddressController.php new file mode 100644 index 0000000..38b7d6f --- /dev/null +++ b/src/controllers/AddressController.php @@ -0,0 +1,80 @@ +requireAcceptsJson(); + + $address = Craft::$app->fields->getFieldByHandle('address'); + + $addressModel = new AddressModel([ + 'countryCode' => Craft::$app->request->post('countryCode') + ]); + + $response = [ + 'html' => Craft::$app->getView()->namespaceInputs($address->renderFormFields($addressModel), Craft::$app->request->post('namespace')) + ]; + + return $this->asJson($response); + } + +} diff --git a/src/controllers/EmbedController.php b/src/controllers/EmbedController.php index 4294835..c781c36 100644 --- a/src/controllers/EmbedController.php +++ b/src/controllers/EmbedController.php @@ -1,8 +1,8 @@ $id, 'name' => $this->handle, - 'namespace' => $namespacedId, + 'namespace' => Craft::$app->getView()->getNamespace(), + 'namespacedId' => $namespacedId, 'prefix' => Craft::$app->getView()->namespaceInputId(''), 'fieldSettings' => $fieldSettings, 'pluginSettings' => $pluginSettings, @@ -209,7 +210,7 @@ public function getInputHtml( * @throws Twig_Error_Loader * @throws RuntimeException */ - protected function renderFormFields(AddressModel $value = null) + public function renderFormFields(AddressModel $value = null) { // Get our id and namespace $id = Craft::$app->getView()->formatInputId($this->handle); @@ -229,6 +230,7 @@ protected function renderFormFields(AddressModel $value = null) 'value' => $countryCode, 'field' => $this, 'id' => $id, + 'namespace' => Craft::$app->getView()->getNamespace(), 'namespacedId' => $namespacedId, 'settings' => $fieldSettings, 'countryOptions' => $this->getCountryOptions(), @@ -245,6 +247,7 @@ protected function renderFormFields(AddressModel $value = null) 'value' => $value, 'field' => $this, 'id' => $id, + 'namespace' => Craft::$app->getView()->getNamespace(), 'namespacedId' => $namespacedId, 'fieldSettings' => $fieldSettings, 'pluginSettings' => $pluginSettings, @@ -337,6 +340,7 @@ private function renderAddressFields($value) 'value' => $value, 'field' => $this, 'id' => $id, + 'namespace' => Craft::$app->getView()->getNamespace(), 'namespacedId' => $namespacedId, 'settings' => $fieldSettings, 'addressFormat' => $addressFormat, diff --git a/src/services/Embed.php b/src/services/Embed.php index 773dbb9..b8ec110 100644 --- a/src/services/Embed.php +++ b/src/services/Embed.php @@ -1,8 +1,8 @@