Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

default value in subarray #132

Open
schsj opened this issue Mar 10, 2016 · 0 comments
Open

default value in subarray #132

schsj opened this issue Mar 10, 2016 · 0 comments

Comments

@schsj
Copy link

schsj commented Mar 10, 2016

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();
}; 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant