Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Carson Brown 15 posts 85 karma points
    Jun 20, 2016 @ 19:15
    Carson Brown
    0

    Setting Form on Custom Tab to Pristine

    I've added a tab to my umbraco back office home page that allows you to edit a config file from the back office. After the form is saved, I would like the form to keep the value but be set pristine instead of staying as dirty, since leaving the page now makes the "you have unsaved changes" tab open. Currently, my code looks like: HTML:

    <div ng-controller="rewriteConfigTabController">
    <form novalidate name="rewriteForm">
        <div>
            <h3><strong>Rewrite Config</strong></h3>
            <div>Use this to change the rewrite maps for Clark Marketing. Remember to build after making changes!</div><br />
            <div>You will need to add a rule for your site to the rewrite section of Web.config.</div><br />
        </div>
        <div name="success" ng-show="successText != null" class="alert alert-success property-error ng-binding">{{successText}}</div>
        <div name="errors" ng-show="errorText != null" class="alert alert-error property-error ng-binding">{{errorText}}</div>
        <textarea id="rewriteEditor" ng-model="configText" rows="30" cols="150"></textarea><br />
        <umb-button type="button" action="save(configText)" label="Save" button-style="success"></umb-button>
    </form>
    

    Validation where we would be setting it to pristine:

    function validateTextboxXml(text,scope) {
    var Module = {
        xml: text,
        schema: xmlSchema,
        arguments: ["--noout", "--schema", "xml", "schema"]
    };
    var errors = validateXML(Module);
    if (errors.substring(0, 16) == 'schema validates') {            //errors == "schema validates\n" when this is true
        scope.successText = "Rewrites updated.";
        scope.errorText = null;
        scope.rewriteForm.$pristine = true;
        scope.rewriteForm.$dirty = false;
        return true;
    }
    else {
        scope.errorText = errors;
        scope.successText = null;
        return false;
    }
    

    }

    When this runs the form is still dirty after going through. Any help would be appreciated, Thanks. Carson

  • David Brendel 774 posts 2843 karma points c-trib
    Jun 21, 2016 @ 14:49
    David Brendel
    0

    Hi Carson,

    I'm using this call to clear the form: $scope.organiserForm.$setPristine();

    Where "organiserForm" should be the name of your Form.

    Regards David

  • Markus Johansson 1658 posts 4727 karma points c-trib
    Feb 19, 2020 @ 13:31
    Markus Johansson
    0

    Just in case someone is looking for a solution for this when having a form inside a dashboard in Umbraco 8.

    Turns out that all tabs in the any dashboard are wrapped in a

    so this

    $scope.organiserForm.$setPristine();
    

    Would only set your own form to Pristine but it would leave the wrapping "dashboardForm" as dirty hence showing the confirmation. To get around this you need to set both forms as Pristine

    $scope.organiserForm.$setPristine(); // reset my own form
    $scope.dashboardForm.$setPristine(); // reset wrapping form
    

    Hope this helps anyone having the same issue.

Please Sign in or register to post replies

Write your reply to:

Draft