0
votes

I have this Schema :

Schemas = {};

Schemas.Id = {
    type: String,
    optional: true,
    label: 'Id',
    //max: ID_LENGTH,
    defaultValue : Random.id(ID_LENGTH),
    denyUpdate: true
};

Schemas.Name = {
    type: String,
    label: 'Name',
    max: 75
};

Schemas.Description = {
    type: String,
    label: 'Description',
    max: 500,
    optional: true,
    autoform: {
        rows: 5
    }
};

//-- Attribute
Schemas.Attribute = {
    _id: Schemas.Id,
    attribute_name : Schemas.Name,
    attribute_description : Schemas.Description
};

Collections.Attributes.attachSchema(Schemas.Attribute);

i have a request from client they can insert _id manually. but autoform cant permit it, this the template :

<template name="pg_attr_insert">
    {{#autoForm _id="afInsertDemo" type="insert" collection=Collections.Attributes}}
        <div class="form-group {{#if afFieldIsInvalid name='_id'}}has-error{{/if}}">
            <label class="control-label">{{afFieldLabelText name='_id'}}</label>
            {{> afFieldInput name='_id'}}
            {{#if afFieldIsInvalid name='_id'}}
                <span class="help-block">{{{afFieldMessattribute_description name='_id'}}}</span>
            {{/if}}
        </div>
        <div class="form-group {{#if afFieldIsInvalid name='attribute_name'}}has-error{{/if}}">
            <label class="control-label">{{afFieldLabelText name='attribute_name'}}</label>
            {{> afFieldInput name='attribute_name'}}
            {{#if afFieldIsInvalid name='attribute_name'}}
                <span class="help-block">{{{afFieldMessattribute_description name='attribute_name'}}}</span>
            {{/if}}
        </div>
        <div class="form-group {{#if afFieldIsInvalid name='attribute_description'}}has-error{{/if}}">
            <label class="control-label">{{afFieldLabelText name='attribute_description'}}</label>
            {{> afFieldInput name='attribute_description'}}
            {{#if afFieldIsInvalid name='attribute_description'}}
                <span class="help-block">{{{afFieldMessattribute_description name='attribute_description'}}}</span>
            {{/if}}
        </div>
        <div class="form-group">
            <button type="submit" class="btn btn-primary">Add Person</button>
            <button type="reset" class="btn btn-default">Reset Form</button>
        </div>
    {{/autoForm}}
</template>

this is the error :

Uncaught Error: Every autoForm and quickForm must have an "id" attribute set to a unique string.

is there anyway autoform permit insert _id manually? and how?

1
You could create your own ID field that gets displayed and keep the _id field hidden from users.Mark Leiber
i try it, but it didnt work when submit, i mean it getting error and no data insertedyozawiratama

1 Answers

0
votes

Oke i know my false, i create

{{#autoForm _id="afInsertDemo" type="insert" collection=Collections.Attributes}}

i just convert it to :

{{#autoForm id="afInsertDemo" type="insert" collection=Collections.Attributes}}