/* * Element methods */ func (e *Element) SetAttrib(id string, name string, value string) bool { isValidAttrib := false //by default value is to false //convert to lowercase //iterate and check if any invalid label string was passed isValidAttrib = stringarray.In_Array(strings.ToLower(id), allowedlist[:]) //check if a valid position name was passed ex: first, last etc if !isValidAttrib { return false } if e.Attribs == nil { e.Attribs = make(map[string][][2]string, 0) } if _, present := e.Attribs[id]; !present { e.Attribs[id] = make([][2]string, 0) } exists := false attribs := e.Attribs[id] for _, attr := range attribs { if attr[0] == name { return false } } if !exists { e.Attribs[id] = append(e.Attribs[id], [...]string{name, value}) } return true // e.Attribs[id] }
func (f *Form) SetMethod(method string) error { if method == "" { filename, callingfuncname, line := formerror.HandleDepth(2) var err = fmt.Sprintf("Expected GET or POST received null instead from %s:%s:%d:\n", filename, callingfuncname, line) return errors.New(err) } isValidMethod := stringarray.In_Array(strings.ToUpper(method), formmethods[:]) //check if a valid position name was passed ex: first, last etc if !isValidMethod { filename, callingfuncname, line := formerror.HandleDepth(2) var err = fmt.Sprintf("Expected GET or POST received %s instead from %s:%s:%d:\n", method, filename, callingfuncname, line) return errors.New(err) } f.Method = strings.ToUpper(method) return nil }
func (f *Form) MoveElementInGroup(groupname string, sourcename string, position string, targetelement string) bool { isValidPosition := stringarray.In_Array(position, []string{"first", "last", "before", "after"}) //check if a valid position name was passed ex: first, last etc if !isValidPosition { return false } sourcematch := false targetmatch := false for _, el := range f.elements { if el.GetbelongsToGroup() == groupname && sourcename == el.GetName() { sourcematch = true } if el.GetbelongsToGroup() == groupname && targetelement == el.GetName() { targetmatch = true } } //if both source & target belong to same group if sourcematch && targetmatch { f.MoveElement(sourcename, position, targetelement) } return true }