Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

CreateOrUpdateAddress - added prefix to instace variable

DanielŻuławski03ddaf303183
diff --git a/src/Web/Grand.Web/Views/Shared/_AddressAttributes.cshtml b/src/Web/Grand.Web/Views/Shared/_AddressAttributes.cshtml
index b309cdde6..7f06d84b4 100644
--- a/src/Web/Grand.Web/Views/Shared/_AddressAttributes.cshtml
+++ b/src/Web/Grand.Web/Views/Shared/_AddressAttributes.cshtml
@@ -1,99 +1,102 @@
@model IList<AddressAttributeModel>
+@{
+ var prefix = ViewData.TemplateInfo.HtmlFieldPrefix;
+}
@foreach (var attribute in Model)
{
string controlId = string.Format("address_attribute_{0}", attribute.Id);
string textPrompt = attribute.Name;
-<div class="inputs custom-attributes col-sm-12 mb-3">
- <label class="col-form-label" for="@(controlId)">@textPrompt:</label>
- @if (attribute.IsRequired)
- {
- <span class="required">*</span>
- }
+ <div class="inputs custom-attributes col-sm-12 mb-3">
+ <label class="col-form-label" for="@(controlId)">@textPrompt:</label>
+ @if (attribute.IsRequired)
+ {
+ <span class="required">*</span>
+ }
- @switch (attribute.AttributeControlType)
- {
- case AttributeControlType.DropdownList:
- {
- <validation-provider @if (attribute.IsRequired) { <text> rules="required" </text> } name="@(controlId)" v-slot="{ errors, classes }">
- <select v-model="createorupdateaddress.@(controlId)" data-val-required="@(string.Format(Loc["Fields.IsRequired"], textPrompt))" v-bind:class="[classes , 'custom-select form-control']" name="@(controlId)" id="@(controlId)">
- @if (!attribute.IsRequired)
+ @switch (attribute.AttributeControlType)
+ {
+ case AttributeControlType.DropdownList:
+ {
+ <validation-provider @if (attribute.IsRequired) { <text> rules="required" </text> } name="@(controlId)" v-slot="{ errors, classes }">
+ <select v-model="createorupdateaddress@{@prefix}.@(controlId)" data-val-required="@(string.Format(Loc["Fields.IsRequired"], textPrompt))" v-bind:class="[classes , 'custom-select form-control']" name="@(controlId)" id="@(controlId)">
+ @if (!attribute.IsRequired)
+ {
+ <option value="">---</option>
+ }
+ @foreach (var attributeValue in attribute.Values)
+ {
+ <option selected="@attributeValue.IsPreSelected" value="@attributeValue.Id">@attributeValue.Name</option>
+ }
+ </select>
+ <span class="field-validation-error">{{ errors[0] }}</span>
+ </validation-provider>
+ }
+ break;
+ case AttributeControlType.RadioList:
+ {
+ <ul class="option-list pl-0">
+ @foreach (var attributeValue in attribute.Values)
{
- <option value="">---</option>
+ <li>
+ <validation-provider tag="li" vid="@(controlId)" @if (attribute.IsRequired) { <text> rules="required" </text> } v-slot="{ errors, classes }">
+ <label for="@(controlId)_@(attributeValue.Id)" class="custom-control custom-radio">
+ <input v-bind:class="[classes , 'custom-control-input']" data-val="true" data-val-required="@(string.Format(Loc["Fields.IsRequired"], textPrompt))" v-model="createorupdateaddress@{@prefix}.@(controlId)" id="@(controlId)_@(attributeValue.Id)" type="radio" name="@(controlId)" value="@(attributeValue.Id)" checked="@attributeValue.IsPreSelected" />
+ <span class="custom-control-label"></span>
+ <span class="custom-control-description">@attributeValue.Name</span>
+ <span class="field-validation-error d-flex w-100">{{ errors[0] }}</span>
+ </label>
+ </validation-provider>
+
+ </li>
}
+ </ul>
+ }
+ break;
+ case AttributeControlType.Checkboxes:
+ case AttributeControlType.ReadonlyCheckboxes:
+ {
+ <ul class="option-list pl-0">
@foreach (var attributeValue in attribute.Values)
{
- <option selected="@attributeValue.IsPreSelected" value="@attributeValue.Id">@attributeValue.Name</option>
- }
- </select>
- <span class="field-validation-error">{{ errors[0] }}</span>
- </validation-provider>
- }
- break;
- case AttributeControlType.RadioList:
- {
- <ul class="option-list pl-0">
- @foreach (var attributeValue in attribute.Values)
- {
- <li>
- <validation-provider tag="li" vid="@(controlId)" @if (attribute.IsRequired) { <text> rules="required" </text> } v-slot="{ errors, classes }">
- <label for="@(controlId)_@(attributeValue.Id)" class="custom-control custom-radio">
- <input v-bind:class="[classes , 'custom-control-input']" data-val="true" data-val-required="@(string.Format(Loc["Fields.IsRequired"], textPrompt))" v-model="createorupdateaddress.@(controlId)" id="@(controlId)_@(attributeValue.Id)" type="radio" name="@(controlId)" value="@(attributeValue.Id)" checked="@attributeValue.IsPreSelected" />
+ <validation-provider tag="li" vid="@(controlId)" @if (attribute.IsRequired) { <text> :rules="{ required: { allowFalse: false } }" </text> } v-slot="{ errors, classes }">
+ <label class="custom-control custom-checkbox">
+ <input v-bind:class="[classes , 'custom-control-input']" data-val="true" data-val-required="@(string.Format(Loc["Fields.IsRequired"], textPrompt))" v-model="createorupdateaddress@{@prefix}.@(controlId)" id="@(controlId)_@(attributeValue.Id)" type="checkbox" name="@(controlId)" value="@(attributeValue.Id)" checked="@attributeValue.IsPreSelected" @(attribute.AttributeControlType == AttributeControlType.ReadonlyCheckboxes ? Html.Raw(" disabled=\"disabled\"") : null) />
<span class="custom-control-label"></span>
<span class="custom-control-description">@attributeValue.Name</span>
<span class="field-validation-error d-flex w-100">{{ errors[0] }}</span>
</label>
</validation-provider>
-
- </li>
- }
- </ul>
- }
- break;
- case AttributeControlType.Checkboxes:
- case AttributeControlType.ReadonlyCheckboxes:
- {
- <ul class="option-list pl-0">
- @foreach (var attributeValue in attribute.Values)
- {
- <validation-provider tag="li" vid="@(controlId)" @if (attribute.IsRequired) { <text> :rules="{ required: { allowFalse: false } }" </text> } v-slot="{ errors, classes }">
- <label class="custom-control custom-checkbox">
- <input v-bind:class="[classes , 'custom-control-input']" data-val="true" data-val-required="@(string.Format(Loc["Fields.IsRequired"], textPrompt))" v-model="createorupdateaddress.@(controlId)" id="@(controlId)_@(attributeValue.Id)" type="checkbox" name="@(controlId)" value="@(attributeValue.Id)" checked="@attributeValue.IsPreSelected" @(attribute.AttributeControlType == AttributeControlType.ReadonlyCheckboxes ? Html.Raw(" disabled=\"disabled\"") : null) />
- <span class="custom-control-label"></span>
- <span class="custom-control-description">@attributeValue.Name</span>
- <span class="field-validation-error d-flex w-100">{{ errors[0] }}</span>
- </label>
- </validation-provider>
- }
- </ul>
- }
- break;
- case AttributeControlType.TextBox:
- {
- <validation-provider @if (attribute.IsRequired) { <text> rules="required" </text> } name="@(controlId)" v-slot="{ errors, classes }">
- <input name="@(controlId)" type="text"
- id="@(controlId)" v-model="createorupdateaddress.@(controlId)" data-val-required="@(string.Format(Loc["Fields.IsRequired"], textPrompt))" v-bind:class="[classes , 'form-control textbox']" />
- <span class="field-validation-error">{{ errors[0] }}</span>
- </validation-provider>
- }
- break;
- case AttributeControlType.MultilineTextbox:
- {
- <validation-provider @if (attribute.IsRequired) { <text> rules="required" </text> } name="@(controlId)" v-slot="{ errors, classes }">
- <textarea name="@(controlId)"
- id="@(controlId)" v-model="createorupdateaddress.@(controlId)" data-val-required="@(string.Format(Loc["Fields.IsRequired"], textPrompt))" v-bind:class="[classes , 'form-control']"></textarea>
- <span class="field-validation-error">{{ errors[0] }}</span>
- </validation-provider>
- }
- break;
- case AttributeControlType.Datepicker:
- case AttributeControlType.FileUpload:
- case AttributeControlType.ColorSquares:
- case AttributeControlType.ImageSquares:
- {
- //not support attribute type
- }
- break;
- }
-</div>
+ }
+ </ul>
+ }
+ break;
+ case AttributeControlType.TextBox:
+ {
+ <validation-provider @if (attribute.IsRequired) { <text> rules="required" </text> } name="@(controlId)" v-slot="{ errors, classes }">
+ <input name="@(controlId)" type="text"
+ id="@(controlId)" v-model="createorupdateaddress@{@prefix}.@(controlId)" data-val-required="@(string.Format(Loc["Fields.IsRequired"], textPrompt))" v-bind:class="[classes , 'form-control textbox']" />
+ <span class="field-validation-error">{{ errors[0] }}</span>
+ </validation-provider>
+ }
+ break;
+ case AttributeControlType.MultilineTextbox:
+ {
+ <validation-provider @if (attribute.IsRequired) { <text> rules="required" </text> } name="@(controlId)" v-slot="{ errors, classes }">
+ <textarea name="@(controlId)"
+ id="@(controlId)" v-model="createorupdateaddress@{@prefix}.@(controlId)" data-val-required="@(string.Format(Loc["Fields.IsRequired"], textPrompt))" v-bind:class="[classes , 'form-control']"></textarea>
+ <span class="field-validation-error">{{ errors[0] }}</span>
+ </validation-provider>
+ }
+ break;
+ case AttributeControlType.Datepicker:
+ case AttributeControlType.FileUpload:
+ case AttributeControlType.ColorSquares:
+ case AttributeControlType.ImageSquares:
+ {
+ //not support attribute type
+ }
+ break;
+ }
+ </div>
}
diff --git a/src/Web/Grand.Web/Views/Shared/_CreateOrUpdateAddress.cshtml b/src/Web/Grand.Web/Views/Shared/_CreateOrUpdateAddress.cshtml
index 1df0c7e5d..ec6ec8d8b 100644
--- a/src/Web/Grand.Web/Views/Shared/_CreateOrUpdateAddress.cshtml
+++ b/src/Web/Grand.Web/Views/Shared/_CreateOrUpdateAddress.cshtml
@@ -20,7 +20,7 @@
elChild.innerHTML = id.name;
ddlStates.appendChild(elChild);
});
- createorupdateaddress.StateProvinceId = response.data[0].id;
+ createorupdateaddress@{@prefix}.StateProvinceId = response.data[0].id;
}).then(function () {
ddlStates.classList.remove('is-valid');
ddlStates.classList.add('is-invalid');
@@ -46,7 +46,7 @@
<validation-provider tag="div" rules="required" :name="'@prefix' + '.FirstName'" v-slot="{ errors, classes }">
<label asp-for="FirstName" class="col-form-label">@Loc["Address.Fields.FirstName"]:</label>
<span class="required">*</span>
- <input asp-for="FirstName" v-model="createorupdateaddress.FirstName" v-bind:class="[classes , 'form-control']" />
+ <input asp-for="FirstName" v-model="createorupdateaddress@{@prefix}.FirstName" v-bind:class="[classes , 'form-control']" />
<span class="field-validation-error">{{ errors[0] }}</span>
<span asp-validation-for="FirstName"></span>
</validation-provider>
@@ -55,7 +55,7 @@
<validation-provider tag="div" rules="required" :name="'@prefix' + '.LastName'" v-slot="{ errors, classes }">
<label asp-for="LastName" class="col-form-label">@Loc["Address.Fields.LastName"]:</label>
<span class="required">*</span>
- <input asp-for="LastName" v-model="createorupdateaddress.LastName" v-bind:class="[classes , 'form-control']" />
+ <input asp-for="LastName" v-model="createorupdateaddress@{@prefix}.LastName" v-bind:class="[classes , 'form-control']" />
<span class="field-validation-error">{{ errors[0] }}</span>
<span asp-validation-for="LastName"></span>
</validation-provider>
@@ -64,7 +64,7 @@
<validation-provider tag="div" rules="required|email" :name="'@prefix' + '.Email'" v-slot="{ errors, classes }">
<label asp-for="Email" class="col-form-label">@Loc["Address.Fields.Email"]:</label>
<span class="required">*</span>
- <input asp-for="Email" v-model="createorupdateaddress.Email" v-bind:class="[classes , 'form-control']" />
+ <input asp-for="Email" v-model="createorupdateaddress@{@prefix}.Email" v-bind:class="[classes , 'form-control']" />
<span class="field-validation-error">{{ errors[0] }}</span>
<span asp-validation-for="Email"></span>
</validation-provider>
@@ -77,7 +77,7 @@
<validation-provider tag="div" rules="required" :name="'@prefix' + '.Company'" v-slot="{ errors, classes }">
<label asp-for="Company" class="col-form-label">@Loc["Address.Fields.Company"]:</label>
<span class="required">*</span>
- <input asp-for="Company" v-model="createorupdateaddress.Company" v-bind:class="[classes , 'form-control']" />
+ <input asp-for="Company" v-model="createorupdateaddress@{@prefix}.Company" v-bind:class="[classes , 'form-control']" />
<span class="field-validation-error">{{ errors[0] }}</span>
<span asp-validation-for="Company"></span>
</validation-provider>
@@ -98,7 +98,7 @@
<validation-provider tag="div" rules="required" :name="'@prefix' + '.VatNumber'" v-slot="{ errors, classes }">
<label asp-for="VatNumber" class="col-form-label">@Loc["Address.Fields.VatNumber"]:</label>
<span class="required">*</span>
- <input asp-for="VatNumber" v-model="createorupdateaddress.VatNumber" v-bind:class="[classes , 'form-control']" />
+ <input asp-for="VatNumber" v-model="createorupdateaddress@{@prefix}.VatNumber" v-bind:class="[classes , 'form-control']" />
<span class="field-validation-error">{{ errors[0] }}</span>
<span asp-validation-for="VatNumber"></span>
</validation-provider>
@@ -118,7 +118,7 @@
<label asp-for="CountryId" class="col-form-label">@Loc["Address.Fields.Country"]:</label>
<span class="required">*</span>
<select asp-for="CountryId" asp-items="Model.AvailableCountries"
- onchange="@Html.IdFor(model => model.CountryId)_select_element(this)" v-bind:class="[classes , 'form-control custom-select']" v-model="createorupdateaddress.CountryId"></select>
+ onchange="@Html.IdFor(model => model.CountryId)_select_element(this)" v-bind:class="[classes , 'form-control custom-select']" v-model="createorupdateaddress@{@prefix}.CountryId"></select>
<span class="field-validation-error">{{ errors[0] }}</span>
<span asp-validation-for="CountryId"></span>
</validation-provider>
@@ -132,7 +132,7 @@
<label asp-for="StateProvinceId" class="col-form-label">@Loc["Address.Fields.StateProvince"]:</label>
<span class="required">*</span>
<select asp-for="StateProvinceId" data-val-required="@Loc["Address.Fields.StateProvince.Required"]" v-bind:class="[classes , 'form-control custom-select']"
- onchange="@Html.IdFor(model => model.StateProvinceId)_select_element(this)" asp-items="Model.AvailableStates" v-model="createorupdateaddress.StateProvinceId"></select>
+ onchange="@Html.IdFor(model => model.StateProvinceId)_select_element(this)" asp-items="Model.AvailableStates" v-model="createorupdateaddress@{@prefix}.StateProvinceId"></select>
<span class="field-validation-error">{{ errors[0] }}</span>
<span asp-validation-for="StateProvinceId"></span>
</validation-provider>
@@ -146,7 +146,7 @@
<validation-provider tag="div" rules="required" :name="'@prefix' + '.City'" v-slot="{ errors, classes }">
<label asp-for="City" class="col-form-label">@Loc["Address.Fields.City"]:</label>
<span class="required">*</span>
- <input asp-for="City" v-model="createorupdateaddress.City" v-bind:class="[classes , 'form-control']" />
+ <input asp-for="City" v-model="createorupdateaddress@{@prefix}.City" v-bind:class="[classes , 'form-control']" />
<span class="field-validation-error">{{ errors[0] }}</span>
<span asp-validation-for="City"></span>
</validation-provider>
@@ -167,7 +167,7 @@
<validation-provider tag="div" rules="required" :name="'@prefix' + '.Address1'" v-slot="{ errors, classes }">
<label asp-for="Address1" class="col-form-label">@Loc["Address.Fields.Address1"]:</label>
<span class="required">*</span>
- <input asp-for="Address1" v-model="createorupdateaddress.Address1" v-bind:class="[classes , 'form-control']" />
+ <input asp-for="Address1" v-model="createorupdateaddress@{@prefix}.Address1" v-bind:class="[classes , 'form-control']" />
<span class="field-validation-error">{{ errors[0] }}</span>
<span asp-validation-for="Address1"></span>
</validation-provider>
@@ -188,7 +188,7 @@
<validation-provider tag="div" rules="required" :name="'@prefix' + '.Address2'" v-slot="{ errors, classes }">
<label asp-for="Address2" class="col-form-label">@Loc["Address.Fields.Address2"]:</label>
<span class="required">*</span>
- <input asp-for="Address2" v-model="createorupdateaddress.Address2" v-bind:class="[classes , 'form-control']" />
+ <input asp-for="Address2" v-model="createorupdateaddress@{@prefix}.Address2" v-bind:class="[classes , 'form-control']" />
<span class="field-validation-error">{{ errors[0] }}</span>
<span asp-validation-for="Address2"></span>
</validation-provider>
@@ -209,7 +209,7 @@
<validation-provider tag="div" rules="required" :name="'@prefix' + '.ZipPostalCode'" v-slot="{ errors, classes }">
<label asp-for="ZipPostalCode" class="col-form-label">@Loc["Address.Fields.ZipPostalCode"]:</label>
<span class="required">*</span>
- <input asp-for="ZipPostalCode" v-model="createorupdateaddress.ZipPostalCode" v-bind:class="[classes , 'form-control']" />
+ <input asp-for="ZipPostalCode" v-model="createorupdateaddress@{@prefix}.ZipPostalCode" v-bind:class="[classes , 'form-control']" />
<span class="field-validation-error">{{ errors[0] }}</span>
<span asp-validation-for="ZipPostalCode"></span>
</validation-provider>
@@ -230,7 +230,7 @@
<validation-provider tag="div" rules="required" :name="'@prefix' + '.PhoneNumber'" v-slot="{ errors, classes }">
<label asp-for="PhoneNumber" class="col-form-label">@Loc["Address.Fields.PhoneNumber"]:</label>
<span class="required">*</span>
- <input asp-for="PhoneNumber" v-model="createorupdateaddress.PhoneNumber" v-bind:class="[classes , 'form-control']" />
+ <input asp-for="PhoneNumber" v-model="createorupdateaddress@{@prefix}.PhoneNumber" v-bind:class="[classes , 'form-control']" />
<span class="field-validation-error">{{ errors[0] }}</span>
<span asp-validation-for="PhoneNumber"></span>
</validation-provider>
@@ -251,7 +251,7 @@
<validation-provider tag="div" rules="required" :name="'@prefix' + '.FaxNumber'" v-slot="{ errors, classes }">
<label asp-for="FaxNumber" class="col-form-label">@Loc["Address.Fields.FaxNumber"]:</label>
<span class="required">*</span>
- <input asp-for="FaxNumber" v-model="createorupdateaddress.FaxNumber" v-bind:class="[classes , 'form-control']" />
+ <input asp-for="FaxNumber" v-model="createorupdateaddress@{@prefix}.FaxNumber" v-bind:class="[classes , 'form-control']" />
<span class="field-validation-error">{{ errors[0] }}</span>
<span asp-validation-for="FaxNumber"></span>
</validation-provider>
@@ -286,7 +286,7 @@
<div id="errors-address"></div>
</div>
<script asp-location="Footer" asp-order="301">
- var createorupdateaddress = new Vue({
+ var createorupdateaddress@{@prefix} = new Vue({
data: () => ({
@{
<text>
@@ -311,5 +311,5 @@
</text>
}
})
- });
+ });
</script>
\ No newline at end of file