Skip to content

default value in subarray #132

@schsj

Description

@schsj

Hi, I have simple scheme with subarray. Tell me please, how can I set random id to each element of them? result: http://prntscr.com/adg79g

var randId={
type:String,
default:getRand
};
var testShema=mongoose.Schema({
    field:randId,
    object:{field1:randId,field2:randId},
    array:[randId]
})

I try to use formageField like this https://github.com/node4good/formage/wiki/Custom-Fields , but randId of each element are equal. case result: http://prntscr.com/adgfcd
UPD:
Resolved by schema setter, but question with defaul value within arrow still opened

var ReadOnlyWidget = formage.widgets.TextWidget.extend({
    render: function (res) {
        this.attrs.readonly='readonly';
        this._super(res);
    }
});

var ReadOnly = formage.fields.StringField.extend({
    init: function (options) {
        options = options || {};
        options.widget = ReadOnlyWidget;
        this._super(options);
    }
});

var randId={
        type:String, 
        formageField:ReadOnly, 
        set: function(v){return v||getRand();
}; 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions