Copied to clipboard

Flag this post as spam?

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


  • Christian Hansen 10 posts 100 karma points
    Sep 18, 2018 @ 11:54
    Christian Hansen
    0

    Formulate set hidden field

    Hello, i have created a form with the plugin formulate.

    I now want to have a hidden field. I have created the hidden field and i can see it in my form in the html.

    But it just shows the field as an div not an input.

    <div ng-class="['formulate__field--' + fieldCtrl.fieldType, fieldCtrl.getFieldClass(fieldCtrl.alias)]" ng-if="ctrl.showField(field.id)" class="formulate__field ng-scope ng-isolate-scope formulate__field--hidden formulate__field-alias--hidden" field-id="3bb04875310447cc8526c06efd429799"><div class="formulate__group form-group ng-scope"></div></div>
    

    So have can i set the value of the hidden field?

  • Nicholas Westby 1883 posts 6259 karma points c-trib
    Sep 19, 2018 @ 01:45
    Nicholas Westby
    100

    Funny you should ask. A coworker of mine just asked this and come up with something like this:

    $scope.$on("Formulate.submit", function(event, data) {
        var newData = { 'SomeGuidHere': 'Some Value' };
        data.postData = angular.extend({}, data.postData, newData);
    });
    

    Below are some other options.

    Set Initial Value

    If you look in the main CSHTML file, you'll notice initialValue is being set based on a query string. You can actually set this according to any logic you desire.

    Text Constant Fields

    Instead of a hidden field, you can use a text constant field. That allows you to enter the value in the Formulate section (if the value does not change).

    Form Submission Event

    There is an event you can hook into on the server side when the form is submitting that allows you to alter field values.

    Let me know if any of these approaches sounds like it'd fit your scenario and I can give you some additional information.

  • Christian Hansen 10 posts 100 karma points
    Sep 19, 2018 @ 13:15
    Christian Hansen
    0

    Hello Nicholas,

    Thanks for reply.

    If i have a formulate form with a textbox for name and then a hiddenfield with field alias "test"

    enter image description here How can i then set the hiddenfield to a value. What should i write in the "SomeGuidHere" i have tried with the formulate field-id but i dont insert the value.

    $scope.$on("Formulate.submit", function (event, data) {
        var newData = { '3bb04875310447cc8526c06efd429799': 'Test of hidden field' };
        data.postData = angular.extend({}, data.postData, newData);
    });
    

    Can you help more?

  • Christian Hansen 10 posts 100 karma points
    Sep 20, 2018 @ 06:33
    Christian Hansen
    1

    Hello Nicholas,

    I managed to get it to work with your code.

    Thanks!

  • Nicholas Westby 1883 posts 6259 karma points c-trib
    Sep 20, 2018 @ 15:50
    Nicholas Westby
    0

    Happy to hear it :-)

Please Sign in or register to post replies

Write your reply to:

Draft