Adding tab via plugin in version 3.80

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
7 years ago
How does one SAVE the fields on the custom tab?

(I have an older version of this where the custom tab has its own Save button and uses Ajax to call may SaveX Action, but I'd hope that the regular 'Save' or 'Save and Continue' buttons at the top-right pf page would now save my fields too.)
7 years ago
Also, how does one use  @Html.RequiredHint() following @Html.NopEditorFor?  - the "*" is appearing on the next line.
7 years ago
bump :)
7 years ago
hi
7 years ago
New York wrote:
How does one SAVE the fields on the custom tab?

(I have an older version of this where the custom tab has its own Save button and uses Ajax to call may SaveX Action, but I'd hope that the regular 'Save' or 'Save and Continue' buttons at the top-right pf page would now save my fields too.)


using the old ajax version, cant see any other way
7 years ago
@hezyz
Thanks, but it's disappointing that there's a clean way to add admin custom page tabs, but not to be able to use the page save buttons.  I thought there would be a cleaner way.  I suspect I can add JavaScript to detect the onclick of the current Save (or Save and continue) buttons, and do my Ajax call then.
7 years ago
New York wrote:
@hezyz
Thanks, but it's disappointing that there's a clean way to add admin custom page tabs, but not to be able to use the page save buttons.  I thought there would be a cleaner way.  I suspect I can add JavaScript to detect the onclick of the current Save (or Save and continue) buttons, and do my Ajax call then.


i use the following:


<script type="text/javascript">
    $(document).ready(function () {
        $("#button-save").click(function () {
            $("#returned-message").html("");
            var model = { id: $("#Id").val(), productid: $("#Productid").val() };
            $.post("@(Url.RouteUrl("Plugin.Misc.Product.SaveProduct"))", model, function () {
                $("#returned-message").html("@T("Nop.Plugin.Misc.Product.Saved")");
            });
        });
    });
</script>
7 years ago
just posted a full project with a tab and save button

made by Andy Mckenna

https://www.nopcommerce.com/boards/t/25607/license-key-plugin.aspx?p=4
7 years ago
In case anyone is interested, I've got the normal "save" buttons (top-right of page) to work with a custom admin Vendor tab (with several fields):


    $(document).ready(function () {
        $("button[name = 'save']").click(function () { saveExtendedVendor(); });
        $("button[name = 'save-continue']").click(function () { saveExtendedVendor(); });
    });

    function saveExtendedVendor() {
        $.ajax({
            cache: false,
            type: 'POST',
            url: '@Url.RouteUrl("ExtendedVendorSaveVendor")',
            data: $("#vendor-extended-info *").serialize(),
            dataType: 'json',
            error: function (xhr, ajaxOptions, thrownError) { alert(xhr.responseText); }
        });
        return false;
    }


However, the client side validation is not working (e.g. 'required field').  The validator is set up on the class:
    [Validator(typeof(ExtendedVendorEditValidator))]
    public class ExtendedVendorEditModel : BaseNopEntityModel
...

and, this is in the .cshtml file:

<div class="col-md-9">
    @Html.NopEditorFor(model => model.Address1)
    @Html.RequiredHint()
    @Html.ValidationMessageFor(model => model.Address1)
</div>


And, when I inspect the HTML element in the browser, it has the ...class="field-validation-valid" data-valmsg-for=...

<div class="col-md-9">
    <input class="form-control text-box single-line valid" data-val="true" data-val-required="Address Line 1 is required" id="Address1" name="Address1" type="text" value="10 MAIN St">
    <span class="required">*</span>
    <span class="field-validation-valid" data-valmsg-for="Address1" data-valmsg-replace="true"></span>
</div>



I use the same model (& validator) in a custom tab I put in the public vendor edit (in customer account) and it works fine.  It just does not work in the admin vendor edit.

Thoughts anyone?
7 years ago
New York wrote:
In case anyone is interested, I've got the normal "save" buttons (top-right of page) to work with a custom admin Vendor tab (with several fields):


    $(document).ready(function () {
        $("button[name = 'save']").click(function () { saveExtendedVendor(); });
        $("button[name = 'save-continue']").click(function () { saveExtendedVendor(); });
    });

    function saveExtendedVendor() {
        $.ajax({
            cache: false,
            type: 'POST',
            url: '@Url.RouteUrl("ExtendedVendorSaveVendor")',
            data: $("#vendor-extended-info *").serialize(),
            dataType: 'json',
            error: function (xhr, ajaxOptions, thrownError) { alert(xhr.responseText); }
        });
        return false;
    }


However, the client side validation is not working (e.g. 'required field').  The validator is set up on the class:
    [Validator(typeof(ExtendedVendorEditValidator))]
    public class ExtendedVendorEditModel : BaseNopEntityModel
...

and, this is in the .cshtml file:

<div class="col-md-9">
    @Html.NopEditorFor(model => model.Address1)
    @Html.RequiredHint()
    @Html.ValidationMessageFor(model => model.Address1)
</div>


And, when I inspect the HTML element in the browser, it has the ...class="field-validation-valid" data-valmsg-for=...

<div class="col-md-9">
    <input class="form-control text-box single-line valid" data-val="true" data-val-required="Address Line 1 is required" id="Address1" name="Address1" type="text" value="10 MAIN St">
    <span class="required">*</span>
    <span class="field-validation-valid" data-valmsg-for="Address1" data-valmsg-replace="true"></span>
</div>



I use the same model (& validator) in a custom tab I put in the public vendor edit (in customer account) and it works fine.  It just does not work in the admin vendor edit.

Thoughts anyone?


The following js are missing in Admin Layout

  Html.AppendScriptParts("~/Scripts/jquery.validate.unobtrusive.min.js");
    Html.AppendScriptParts("~/Scripts/jquery.validate.min.js");


And also you have submitted data by Ajax. That's why I think it will not work!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.