fields.def not computed if form is not saved

fields.def not computed if form is not saved

LapointeLapointe Posts: 430Questions: 81Answers: 4

hello
I use a def value for a field and set this value to a function using math.random

{ name: 'user.Login', 
    def: GetCode(8, 'aq12wxsze9dcvf47rtgbn56hyujk03iolmp8'.toUpperCase()) 
},

...
    function GetCode(l=8, c='AQW@yu$iopXS123ZEDhjklmwCVFRTGBNn456HYUJdf%gxcKIOt*qs!LMPa&z#e{rvb789'){
        var n = c.length, r = '', l = 8;
        for(i=0; i < l; i++)
        {
            r += c[Math.floor(Math.random() * n)];
        }
        return r;
    ;}  

If the form is closed with no save the def value is not computed again when reopened.

Is there a way to force compute each def values based on function when editor is opened ?

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598
    Answer ✓

    Hi @Lapointe ,

    If you make fields.def a function, like the second example, it may do the trick. Otherwise, you can use the preOpen event.

    Cheers,

    Colin

  • LapointeLapointe Posts: 430Questions: 81Answers: 4

    Hi colin
    Thanks for answer.
    Unfortunately this do not give me a solution.

    I do use a def set to a function, like in second example (function getCode is not anonymous but ...)

    fields: [ 
        { name: 'Email', label: 'Email' },
        { name: 'Login', 
            def: GetCode(8, 'aq12wxsze9dcvf47rtgbn56hyujk03iolmp8'.toUpperCase()) 
            },
    

    Looking field.def I find the computed value, not the function name that was called...

    So how to know in preOpen (or othen) event for each fields in this form if the field def value is set based on a function and if yes then call function when event fired ?

  • LapointeLapointe Posts: 430Questions: 81Answers: 4

    Hi Colin
    I'm sorry.
    You are right. Editor do not know getcode is a callback and then set the def value as static value.
    Thank again

This discussion has been closed.