Copied to clipboard

Flag this post as spam?

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


  • Laurent Lequenne 122 posts 247 karma points
    Feb 01, 2017 @ 10:26
    Laurent Lequenne
    0

    Node Name generation when user saves a new created node

    Hi,

    I have some content types with first and last name for example. When the user creates and saves a new content and did not entered any node name, the backend gives an error as the node name is mandatory.

    I would like to create a node name automatically based on first and last name. Is there a way to do this ? Thanks for any suggestion or sample :)

    Thanks

    Laurent

  • Laurent Lequenne 122 posts 247 karma points
    Feb 01, 2017 @ 15:21
    Laurent Lequenne
    0

    I managed to update the nodename within a certain editor. But at that point apparently the nodename is already invalidated in case it has not been filled in. So The node is not submitted, but somehow the validation is set to OK. If I submit again then it is ok.

    Is there any event I can start, so that the validation or the submission occurs again. I could hope the editorState could have some function to validate the form again ?

        function checkNodeName() {
            var currentEditorState = editorState.getCurrent();
            if (currentEditorState.contentTypeAlias == "pressContact"
                || currentEditorState.contentTypeAlias == "cabinetMember"
                || currentEditorState.contentTypeAlias == "genericMember"
                ) {
                var fn = currentEditorState.tabs[0].properties[0].value.values["en"];
                var ln =  currentEditorState.tabs[0].properties[1].value.values["en"];
    
                if (fn && ln) {
                    currentEditorState.name = fn + "-" + ln;
                }
                editorState.set(currentEditorState);
    
            }
    
  • Laurent Lequenne 122 posts 247 karma points
    Feb 02, 2017 @ 08:37
    Laurent Lequenne
    100

    If you get better ? but actually it's doing what it should :-)

       angular.module("umbraco").controller("Consilium.ExtendedTextBox",
           function ($scope, editorState) {
    
        var beforeSubmit = $scope.model.config.beforeSubmit;
    
        if (beforeSubmit && beforeSubmit != "") {
            var unsubscribe = $scope.$on("formSubmitting", function (ev, args) {
                $scope[beforeSubmit]();
            });
    
            $scope.$on('$destroy', function () {
                unsubscribe();
            });
    
        }
    
    
    
        $scope.checkNodeName = function () {
            checkNodeName();
        }
    
    
        function checkNodeName() {
            try {
                $scope.$apply(function () {
                    var currentEditorState = editorState.getCurrent();
                    if (currentEditorState.contentTypeAlias == "xxx") {
                        var fn = currentEditorState.tabs[0].properties[0].value.values["en"];
                        var ln = currentEditorState.tabs[0].properties[1].value.values["en"];
    
                        if (fn && ln) {
                            currentEditorState.name = fn + "-" + ln;
                        }
    
                        editorState.set(currentEditorState);
                    }
                });
            } catch (e) {
                console.log("Got an error!", e);
                throw e; // rethrow to not marked as handled
            }
        }
    
    });
    
Please Sign in or register to post replies

Write your reply to:

Draft