示例#1
0
func (self *validateAndFormLayoutStructVisitor) BeginSlice(slice *model.MetaData) error {
	if slice.Parent == nil {
		err := self.formLayout.BeginFormContent(self.form, self.context, self.formContent)
		if err != nil {
			return err
		}
	}
	// Add an empty slice field to generate one extra input row for slices
	if !self.isPost && slice.Value.CanSet() && !self.form.IsFieldExcluded(slice) {
		slice.Value.Set(utils.AppendEmptySliceField(slice.Value))
		mongo.InitRefs(self.formModel)
	}
	return self.formLayout.BeginSlice(slice, self.form, self.context, self.formContent)
}
示例#2
0
func (self *setPostValuesStructVisitor) BeginIndexedFields(indexedFields *model.MetaData) error {
	if indexedFields.Kind == model.SliceKind && indexedFields.Value.CanSet() && !self.form.IsFieldExcluded(indexedFields, self.ctx) {
		if lengthStr := self.ctx.Request.FormValue(indexedFields.Selector() + ".length"); lengthStr != "" {
			length, err := strconv.Atoi(lengthStr)
			if err != nil {
				panic(err.Error())
			}
			if length != indexedFields.Value.Len() {
				indexedFields.Value.Set(utils.SetSliceLengh(indexedFields.Value, length))
				mongo.InitRefs(self.formModel)
			}
		}
	}
	return nil
}
示例#3
0
func (self *setPostValuesStructVisitor) BeginSlice(slice *model.MetaData) error {
	if slice.Value.CanSet() && !self.form.IsFieldExcluded(slice) {
		if lengthStr := self.context.Request.FormValue(slice.Selector() + ".length"); lengthStr != "" {
			length, err := strconv.Atoi(lengthStr)
			if err != nil {
				panic(err.Error())
			}
			if length != slice.Value.Len() {
				slice.Value.Set(utils.SetSliceLengh(slice.Value, length))
				mongo.InitRefs(self.formModel)
			}
		}
	}
	return nil
}
示例#4
0
func (self *validateAndFormLayoutStructVisitor) BeginIndexedFields(indexedFields *model.MetaData) error {
	if indexedFields.Parent == nil {
		err := self.formLayout.BeginFormContent(self.form, self.ctx, self.formContent)
		if err != nil {
			return err
		}
	}
	if self.form.IsFieldExcluded(indexedFields, self.ctx) {
		return nil
	}
	// Add an empty indexedFields field to generate one extra input row for indexedFieldss
	if indexedFields.Kind == model.SliceKind && !self.isPost && indexedFields.Value.CanSet() {
		indexedFields.Value.Set(utils.AppendEmptySliceField(indexedFields.Value))
		mongo.InitRefs(self.formModel)
	}
	return self.formLayout.BeginIndexedFields(indexedFields, self.form, self.ctx, self.formContent)
}