// // Form.swift // HTMLStandard // // Generated on 09/23/2025. // THIS FILE IS GENERATED. DO NOT EDIT. // import Foundation ///
User-submittable form public class Form : HTMLNode, IFlow, IPalpable { public enum Autocomplete : String, CaseIterable { case off case on public init?(rawValue: Substring) { guard let value = Self.allCases.first(where: { $0.rawValue == rawValue }) else { return nil } self = value } public init(expect: Substring) throws { guard let value = Self.allCases.first(where: { $0.rawValue == expect }) else { throw AppError("Unexpected value for Autocomplete: \(expect)") } self = value } public init(expect: String) throws { guard let result = Autocomplete(rawValue: expect) else { throw AppError("Unexpected value for Autocomplete: \(expect)") } self = result } static func parseList(_ value:String?, _ separator:String = " ") throws -> [Autocomplete] { guard let value = value else { return [] } var iterator = value.componentsIterator(separatedBy: separator) let result = try iterator.map { input in return try expect(Autocomplete(rawValue: input), "unexpected value for Autocomplete: \(input)") } return result } } public enum Enctype : String, CaseIterable { case application_xWwwFormUrlencoded = "application/x-www-form-urlencoded" case multipart_formData = "multipart/form-data" case text_plain = "text/plain" public init?(rawValue: Substring) { guard let value = Self.allCases.first(where: { $0.rawValue == rawValue }) else { return nil } self = value } public init(expect: Substring) throws { guard let value = Self.allCases.first(where: { $0.rawValue == expect }) else { throw AppError("Unexpected value for Enctype: \(expect)") } self = value } public init(expect: String) throws { guard let result = Enctype(rawValue: expect) else { throw AppError("Unexpected value for Enctype: \(expect)") } self = result } static func parseList(_ value:String?, _ separator:String = " ") throws -> [Enctype] { guard let value = value else { return [] } var iterator = value.componentsIterator(separatedBy: separator) let result = try iterator.map { input in return try expect(Enctype(rawValue: input), "unexpected value for Enctype: \(input)") } return result } } public enum Method : String, CaseIterable { case GET case POST case dialog public init?(rawValue: Substring) { guard let value = Self.allCases.first(where: { $0.rawValue == rawValue }) else { return nil } self = value } public init(expect: Substring) throws { guard let value = Self.allCases.first(where: { $0.rawValue == expect }) else { throw AppError("Unexpected value for Method: \(expect)") } self = value } public init(expect: String) throws { guard let result = Method(rawValue: expect) else { throw AppError("Unexpected value for Method: \(expect)") } self = result } static func parseList(_ value:String?, _ separator:String = " ") throws -> [Method] { guard let value = value else { return [] } var iterator = value.componentsIterator(separatedBy: separator) let result = try iterator.map { input in return try expect(Method(rawValue: input), "unexpected value for Method: \(input)") } return result } } /// Character encodings to use for form submission. ASCII case-insensitive match for "UTF-8". public var accept_charset:String? = nil /// URL to use for form submission. Valid non-empty URL potentially surrounded by spaces. public var action:URL? = nil /// Default setting for autofill feature for controls in the form. public var autocomplete:Autocomplete? = nil /// Entry list encoding type to use for form submission. public var enctype:Enctype? = nil /// Variant to use for form submission. public var method:Method? = nil /// Name of form to use in the document.forms API. Text. The actual rules are more complicated than indicated. public var name:String? = nil /// Bypass form control validation for form submission. public var novalidate:Bool = false /// Browsing context for form submission. Valid browsing context name or keyword. public var target:String? = nil public init(_ attributes:[String:String], _ parser:XMLParser? = nil) throws { var globalAttr = GlobalAttributesBuilder() for (key, attValue) in attributes { switch (key) { case "accept-charset": accept_charset = attValue continue case "action": action = try URL(expect: attValue) continue case "autocomplete": autocomplete = try Autocomplete(expect: attValue) continue case "enctype": enctype = try Enctype(expect: attValue) continue case "method": method = try Method(expect: attValue) continue case "name": name = attValue continue case "novalidate": novalidate = true continue case "target": target = attValue continue default: break } if globalAttr.trySetGlobalAttribute(key, attValue) { continue } continue } var allItems:[HTMLNode] = [] while let obj = try parser?.readObject(endTag: "form", xmlToHtmlMapper) { allItems.append(obj) } super.init(globalAttr, allItems) } public func addChild(_ someElement:IFlow) { children.append(someElement) } public override func renderAttributes() -> String { var result = super.renderAttributes() if let accept_charset = accept_charset { result += " accept-charset='\(accept_charset)'" } if let action = action { result += " action='\(action.absoluteString)'" } if let autocomplete = autocomplete { result += " autocomplete='\(autocomplete.rawValue)'" } if let enctype = enctype { result += " enctype='\(enctype.rawValue)'" } if let method = method { result += " method='\(method.rawValue)'" } if let name = name { result += " name='\(name)'" } if novalidate { result += " novalidate" } if let target = target { result += " target='\(target)'" } return result } override var nodeName: String { return "form" } override var isVoidElement: Bool { return false } }