Skip to content

Commit

Permalink
Merge pull request #155 from DNNMonster/bugfix/validate-refs
Browse files Browse the repository at this point in the history
Add property ref validation
  • Loading branch information
leedavi authored Jun 3, 2021
2 parents e763884 + c3b7666 commit 4f03e8f
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 3 deletions.
3 changes: 3 additions & 0 deletions App_LocalResources/General.ascx.fr-FR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1209,4 +1209,7 @@
<data name="DealerOnly.Text" xml:space="preserve">
<value>Revendeur Seulement</value>
</data>
<data name="RefValidationMessage.Text" xml:space="preserve">
<value>La référence doit être en minuscules alphanumériques uniquement sans espaces vides.</value>
</data>
</root>
3 changes: 3 additions & 0 deletions App_LocalResources/General.ascx.nl-NL.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,9 @@
<data name="owner.Text" xml:space="preserve">
<value>Eigenaar</value>
</data>
<data name="RefValidationMessage.Text" xml:space="preserve">
<value>Ref mag alleen in kleine letters alfanumeriek zijn zonder lege spaties.</value>
</data>
<data name="PropertyGroupAddSearchBox.Text" xml:space="preserve">
<value>Zoekvak toevoegen</value>
</data>
Expand Down
3 changes: 3 additions & 0 deletions App_LocalResources/General.ascx.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,9 @@
<data name="Carttotal.Text" xml:space="preserve">
<value>Subtotal</value>
</data>
<data name="RefValidationMessage.Text" xml:space="preserve">
<value>Ref should be lower case alpha numeric only with no empty spaces.</value>
</data>
<data name="PropertyGroupAddSearchBox.Text" xml:space="preserve">
<value>Add Search Box</value>
</data>
Expand Down
3 changes: 3 additions & 0 deletions App_LocalResources/general.ascx.it-IT.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1050,4 +1050,7 @@
<data name="DealerOnly.Text" xml:space="preserve">
<value>Commerciante Solo</value>
</data>
<data name="RefValidationMessage.Text" xml:space="preserve">
<value>Ref dovrebbe essere solo alfanumerico minuscolo senza spazi vuoti.</value>
</data>
</root>
16 changes: 15 additions & 1 deletion Components/Categories/CategoryFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,23 @@ public String DeleteCategory(HttpContext context, string editType = "")
public String CategoryAdminSaveList(HttpContext context)
{
var ajaxInfoList = NBrightBuyUtils.GetAjaxInfoList(context);
var strOut = "";
var regex = new Regex(@"^[a-z0-9]+$");
var isPropertyList = (context.Request.QueryString.Get("cmd") == "property_admin_savelist");

foreach (var nbi in ajaxInfoList)
{

// validate property refs
if (isPropertyList) {
var propertyRef = nbi.GetXmlProperty("genxml/textbox/propertyref");
if (propertyRef != "" && !regex.IsMatch(propertyRef))
{
strOut = "Error: Invalid Ref. Only use lower case alpha numeric values. No spaces. " + propertyRef;
break;
};
}

if (nbi.GetXmlPropertyBool("genxml/hidden/isdirty"))
{
var categoryData = CategoryUtils.GetCategoryData(nbi.GetXmlPropertyInt("genxml/hidden/itemid"), nbi.GetXmlProperty("genxml/hidden/categorylang"));
Expand All @@ -213,7 +227,7 @@ public String CategoryAdminSaveList(HttpContext context)
}
DataCache.ClearCache();
NBrightBuyUtils.RemoveModCachePortalWide(PortalSettings.Current.PortalId);
return "";
return strOut;
}

public String ProductAdminSave(HttpContext context, string editLangCurrent)
Expand Down
1 change: 1 addition & 0 deletions Themes/config/default/Admin_Property.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<input id="selecttaxrate" type="hidden" value="" />
<input id="selectedgroup" type="hidden" value="" />
<input id="nextlang" type="hidden" value="" />
<input id="refvalidationmessage" type="hidden" value="@ResourceKey("General.RefValidationMessage")" />
</span>


Expand Down
20 changes: 18 additions & 2 deletions Themes/config/js/admin_property.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,24 @@

$('#propertyAdmin_cmdSaveList').unbind("click");
$("#propertyAdmin_cmdSaveList").click(function () {
$('.processing').show();
nbxget('property_admin_savelist', '.propertyfields', '', '.propertyitemfields');

var regEx = /[^a-z\d]/i;
var elems = ".propertyitemfields input#propertyref";
var isValid = ($(elems).length > 0);
$(elems).each(function(){
isValid = !(regEx.test($(this).val()));
if (!isValid) {
alert($("#refvalidationmessage").val());
$(this).select();
return false;
}
});

if (isValid) {
$('.processing').show();
nbxget('property_admin_savelist', '.propertyfields', '', '.propertyitemfields');
}

});

$('.categorynametextbox').unbind("change");
Expand Down

0 comments on commit 4f03e8f

Please sign in to comment.