001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.juneau.bean.html5;
018
019import java.net.*;
020
021import org.apache.juneau.*;
022import org.apache.juneau.annotation.*;
023
024/**
025 * DTO for an HTML <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#the-form-element">&lt;form&gt;</a>
026 * element.
027 *
028 * <p>
029 * The form element represents a document section containing interactive controls for submitting
030 * information to a web server. It groups form controls together and defines how the data should
031 * be submitted, including the target URL, HTTP method, and encoding type.
032 *
033 * <h5 class='section'>Examples:</h5>
034 * <p class='bcode w800'>
035 *    <jc>// Simple contact form</jc>
036 *    Form <jv>form1</jv> = <jsm>form</jsm>()
037 *       .action(<js>"/contact"</js>)
038 *       .method(<js>"post"</js>)
039 *       .children(
040 *          <jsm>input</jsm>(<js>"text"</js>).name(<js>"name"</js>).placeholder(<js>"Your Name"</js>),
041 *          <jsm>input</jsm>(<js>"email"</js>).name(<js>"email"</js>).placeholder(<js>"Your Email"</js>),
042 *          <jsm>textarea</jsm>().name(<js>"message"</js>).placeholder(<js>"Your Message"</js>),
043 *          <jsm>button</jsm>().type(<js>"submit"</js>).text(<js>"Send Message"</js>)
044 *       );
045 *
046 *    <jc>// File upload form</jc>
047 *    Form <jv>form2</jv> = <jsm>form</jsm>()
048 *       .action(<js>"/upload"</js>)
049 *       .method(<js>"post"</js>)
050 *       .enctype(<js>"multipart/form-data"</js>)
051 *       .children(
052 *          <jsm>input</jsm>(<js>"file"</js>).name(<js>"file"</js>).accept(<js>"image/*"</js>),
053 *          <jsm>button</jsm>().type(<js>"submit"</js>).text(<js>"Upload"</js>)
054 *       );
055 *
056 *    <jc>// Form with validation</jc>
057 *    Form <jv>form3</jv> = <jsm>form</jsm>()
058 *       .action(<js>"/register"</js>)
059 *       .method(<js>"post"</js>)
060 *       .novalidate(<jk>false</jk>)
061 *       .children(
062 *          <jsm>input</jsm>(<js>"email"</js>).name(<js>"email"</js>).required(<jk>true</jk>),
063 *          <jsm>input</jsm>(<js>"password"</js>).name(<js>"password"</js>).required(<jk>true</jk>),
064 *          <jsm>button</jsm>().type(<js>"submit"</js>).text(<js>"Register"</js>)
065 *       );
066 * </p>
067 *
068 * <p>
069 * The following convenience methods are provided for constructing instances of this bean:
070 * <ul class='javatree'>
071 *    <li class='jc'>{@link HtmlBuilder}
072 *    <ul class='javatree'>
073 *       <li class='jm'>{@link HtmlBuilder#form() form()}
074 *       <li class='jm'>{@link HtmlBuilder#form(String, Object...) form(Object, Object...)}
075 *    </ul>
076 * </ul>
077 * </p>
078 *
079 * <h5 class='section'>See Also:</h5><ul>
080 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanHtml5">juneau-bean-html5</a>
081 * </ul>
082 */
083@Bean(typeName = "form")
084public class Form extends HtmlElementMixed {
085
086   /**
087    * Creates an empty {@link Form} element.
088    */
089   public Form() {}
090
091   /**
092    * Creates a {@link Form} element with the specified {@link Form#action(String)} attribute.
093    *
094    * @param action The {@link Form#action(String)} attribute.
095    */
096   public Form(String action) {
097      action(action);
098   }
099
100   /**
101    * Creates an {@link Form} element with the specified {@link Form#action(String)} attribute and child nodes.
102    *
103    * @param action The {@link Form#action(String)} attribute.
104    * @param children The child nodes.
105    */
106   public Form(String action, Object...children) {
107      action(action).children(children);
108   }
109
110   @Override /* Overridden from HtmlElement */
111   public Form _class(String value) { // NOSONAR - Intentional naming.
112      super._class(value);
113      return this;
114   }
115
116   /**
117    * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-form-accept-charset">accept-charset</a>
118    * attribute.
119    *
120    * <p>
121    * Specifies the character encodings that are accepted for form submission. Multiple encodings
122    * can be specified as a space-separated list.
123    *
124    * <p>
125    * Common values:
126    * <ul>
127    *    <li><js>"UTF-8"</js> - Unicode UTF-8 encoding (default)</li>
128    *    <li><js>"ISO-8859-1"</js> - Latin-1 encoding</li>
129    *    <li><js>"UTF-8 ISO-8859-1"</js> - Multiple encodings</li>
130    * </ul>
131    *
132    * @param value The character encodings accepted for form submission.
133    * @return This object.
134    */
135   public Form acceptcharset(String value) {
136      attr("accept-charset", value);
137      return this;
138   }
139
140   @Override /* Overridden from HtmlElement */
141   public Form accesskey(String value) {
142      super.accesskey(value);
143      return this;
144   }
145
146   /**
147    * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-fs-action">action</a> attribute.
148    *
149    * <p>
150    * URL to use for form submission.
151    *
152    * <p>
153    * The value can be of any of the following types: {@link URI}, {@link URL}, {@link String}.
154    * Strings must be valid URIs.
155    *
156    * <p>
157    * URIs defined by {@link UriResolver} can be used for values.
158    *
159    * @param value The new value for this attribute.
160    * @return This object.
161    */
162   public Form action(String value) {
163      attrUri("action", value);
164      return this;
165   }
166
167   @Override /* Overridden from HtmlElement */
168   public Form attr(String key, Object val) {
169      super.attr(key, val);
170      return this;
171   }
172
173   @Override /* Overridden from HtmlElement */
174   public Form attrUri(String key, Object val) {
175      super.attrUri(key, val);
176      return this;
177   }
178
179   /**
180    * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-form-autocomplete">autocomplete</a>
181    * attribute.
182    *
183    * <p>
184    * Sets the default autocomplete behavior for all form controls within this form.
185    * Individual controls can override this setting.
186    *
187    * <p>
188    * Possible values:
189    * <ul>
190    *    <li><js>"on"</js> - Allow autocomplete (default)</li>
191    *    <li><js>"off"</js> - Disable autocomplete</li>
192    * </ul>
193    *
194    * @param value The default autocomplete behavior for form controls.
195    * @return This object.
196    */
197   public Form autocomplete(String value) {
198      attr("autocomplete", value);
199      return this;
200   }
201
202   @Override /* Overridden from HtmlElementMixed */
203   public Form child(Object value) {
204      super.child(value);
205      return this;
206   }
207
208   @Override /* Overridden from HtmlElementMixed */
209   public Form children(Object...value) {
210      super.children(value);
211      return this;
212   }
213
214   @Override /* Overridden from HtmlElement */
215   public Form contenteditable(Object value) {
216      super.contenteditable(value);
217      return this;
218   }
219
220   @Override /* Overridden from HtmlElement */
221   public Form dir(String value) {
222      super.dir(value);
223      return this;
224   }
225
226   /**
227    * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-fs-enctype">enctype</a> attribute.
228    *
229    * <p>
230    * Specifies how form data should be encoded when submitted to the server.
231    *
232    * <p>
233    * Possible values:
234    * <ul>
235    *    <li><js>"application/x-www-form-urlencoded"</js> - Default encoding (default)</li>
236    *    <li><js>"multipart/form-data"</js> - Used for file uploads</li>
237    *    <li><js>"text/plain"</js> - Plain text encoding</li>
238    * </ul>
239    *
240    * @param value The encoding type for form data submission.
241    * @return This object.
242    */
243   public Form enctype(String value) {
244      attr("enctype", value);
245      return this;
246   }
247
248   @Override /* Overridden from HtmlElement */
249   public Form hidden(Object value) {
250      super.hidden(value);
251      return this;
252   }
253
254   @Override /* Overridden from HtmlElement */
255   public Form id(String value) {
256      super.id(value);
257      return this;
258   }
259
260   @Override /* Overridden from HtmlElement */
261   public Form lang(String value) {
262      super.lang(value);
263      return this;
264   }
265
266   /**
267    * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-fs-method">method</a> attribute.
268    *
269    * <p>
270    * Specifies the HTTP method to use when submitting the form.
271    *
272    * <p>
273    * Possible values:
274    * <ul>
275    *    <li><js>"get"</js> - Form data is sent as URL parameters (default)</li>
276    *    <li><js>"post"</js> - Form data is sent in the request body</li>
277    *    <li><js>"dialog"</js> - Used for forms within dialog elements</li>
278    * </ul>
279    *
280    * @param value The HTTP method for form submission.
281    * @return This object.
282    */
283   public Form method(String value) {
284      attr("method", value);
285      return this;
286   }
287
288   /**
289    * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-form-name">name</a> attribute.
290    *
291    * <p>
292    * Specifies the name of the form. This name can be used to access the form via the
293    * document.forms API and for form submission.
294    *
295    * <p>
296    * The name should be unique within the document and should not contain spaces or special characters.
297    *
298    * @param value The name of the form for API access and submission.
299    * @return This object.
300    */
301   public Form name(String value) {
302      attr("name", value);
303      return this;
304   }
305
306   /**
307    * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-fs-novalidate">novalidate</a> attribute.
308    *
309    * <p>
310    * Disables form validation, allowing the form to be submitted even if validation fails.
311    *
312    * @param value If <jk>true</jk>, disables form validation.
313    * @return This object.
314    */
315   public Form novalidate(Boolean value) {
316      attr("novalidate", value);
317      return this;
318   }
319
320   @Override /* Overridden from HtmlElement */
321   public Form onabort(String value) {
322      super.onabort(value);
323      return this;
324   }
325
326   @Override /* Overridden from HtmlElement */
327   public Form onblur(String value) {
328      super.onblur(value);
329      return this;
330   }
331
332   @Override /* Overridden from HtmlElement */
333   public Form oncancel(String value) {
334      super.oncancel(value);
335      return this;
336   }
337
338   @Override /* Overridden from HtmlElement */
339   public Form oncanplay(String value) {
340      super.oncanplay(value);
341      return this;
342   }
343
344   @Override /* Overridden from HtmlElement */
345   public Form oncanplaythrough(String value) {
346      super.oncanplaythrough(value);
347      return this;
348   }
349
350   @Override /* Overridden from HtmlElement */
351   public Form onchange(String value) {
352      super.onchange(value);
353      return this;
354   }
355
356   @Override /* Overridden from HtmlElement */
357   public Form onclick(String value) {
358      super.onclick(value);
359      return this;
360   }
361
362   @Override /* Overridden from HtmlElement */
363   public Form oncuechange(String value) {
364      super.oncuechange(value);
365      return this;
366   }
367
368   @Override /* Overridden from HtmlElement */
369   public Form ondblclick(String value) {
370      super.ondblclick(value);
371      return this;
372   }
373
374   @Override /* Overridden from HtmlElement */
375   public Form ondurationchange(String value) {
376      super.ondurationchange(value);
377      return this;
378   }
379
380   @Override /* Overridden from HtmlElement */
381   public Form onemptied(String value) {
382      super.onemptied(value);
383      return this;
384   }
385
386   @Override /* Overridden from HtmlElement */
387   public Form onended(String value) {
388      super.onended(value);
389      return this;
390   }
391
392   @Override /* Overridden from HtmlElement */
393   public Form onerror(String value) {
394      super.onerror(value);
395      return this;
396   }
397
398   @Override /* Overridden from HtmlElement */
399   public Form onfocus(String value) {
400      super.onfocus(value);
401      return this;
402   }
403
404   @Override /* Overridden from HtmlElement */
405   public Form oninput(String value) {
406      super.oninput(value);
407      return this;
408   }
409
410   @Override /* Overridden from HtmlElement */
411   public Form oninvalid(String value) {
412      super.oninvalid(value);
413      return this;
414   }
415
416   @Override /* Overridden from HtmlElement */
417   public Form onkeydown(String value) {
418      super.onkeydown(value);
419      return this;
420   }
421
422   @Override /* Overridden from HtmlElement */
423   public Form onkeypress(String value) {
424      super.onkeypress(value);
425      return this;
426   }
427
428   @Override /* Overridden from HtmlElement */
429   public Form onkeyup(String value) {
430      super.onkeyup(value);
431      return this;
432   }
433
434   @Override /* Overridden from HtmlElement */
435   public Form onload(String value) {
436      super.onload(value);
437      return this;
438   }
439
440   @Override /* Overridden from HtmlElement */
441   public Form onloadeddata(String value) {
442      super.onloadeddata(value);
443      return this;
444   }
445
446   @Override /* Overridden from HtmlElement */
447   public Form onloadedmetadata(String value) {
448      super.onloadedmetadata(value);
449      return this;
450   }
451
452   @Override /* Overridden from HtmlElement */
453   public Form onloadstart(String value) {
454      super.onloadstart(value);
455      return this;
456   }
457
458   @Override /* Overridden from HtmlElement */
459   public Form onmousedown(String value) {
460      super.onmousedown(value);
461      return this;
462   }
463
464   @Override /* Overridden from HtmlElement */
465   public Form onmouseenter(String value) {
466      super.onmouseenter(value);
467      return this;
468   }
469
470   @Override /* Overridden from HtmlElement */
471   public Form onmouseleave(String value) {
472      super.onmouseleave(value);
473      return this;
474   }
475
476   @Override /* Overridden from HtmlElement */
477   public Form onmousemove(String value) {
478      super.onmousemove(value);
479      return this;
480   }
481
482   @Override /* Overridden from HtmlElement */
483   public Form onmouseout(String value) {
484      super.onmouseout(value);
485      return this;
486   }
487
488   @Override /* Overridden from HtmlElement */
489   public Form onmouseover(String value) {
490      super.onmouseover(value);
491      return this;
492   }
493
494   @Override /* Overridden from HtmlElement */
495   public Form onmouseup(String value) {
496      super.onmouseup(value);
497      return this;
498   }
499
500   @Override /* Overridden from HtmlElement */
501   public Form onmousewheel(String value) {
502      super.onmousewheel(value);
503      return this;
504   }
505
506   @Override /* Overridden from HtmlElement */
507   public Form onpause(String value) {
508      super.onpause(value);
509      return this;
510   }
511
512   @Override /* Overridden from HtmlElement */
513   public Form onplay(String value) {
514      super.onplay(value);
515      return this;
516   }
517
518   @Override /* Overridden from HtmlElement */
519   public Form onplaying(String value) {
520      super.onplaying(value);
521      return this;
522   }
523
524   @Override /* Overridden from HtmlElement */
525   public Form onprogress(String value) {
526      super.onprogress(value);
527      return this;
528   }
529
530   @Override /* Overridden from HtmlElement */
531   public Form onratechange(String value) {
532      super.onratechange(value);
533      return this;
534   }
535
536   @Override /* Overridden from HtmlElement */
537   public Form onreset(String value) {
538      super.onreset(value);
539      return this;
540   }
541
542   @Override /* Overridden from HtmlElement */
543   public Form onresize(String value) {
544      super.onresize(value);
545      return this;
546   }
547
548   @Override /* Overridden from HtmlElement */
549   public Form onscroll(String value) {
550      super.onscroll(value);
551      return this;
552   }
553
554   @Override /* Overridden from HtmlElement */
555   public Form onseeked(String value) {
556      super.onseeked(value);
557      return this;
558   }
559
560   @Override /* Overridden from HtmlElement */
561   public Form onseeking(String value) {
562      super.onseeking(value);
563      return this;
564   }
565
566   @Override /* Overridden from HtmlElement */
567   public Form onselect(String value) {
568      super.onselect(value);
569      return this;
570   }
571
572   @Override /* Overridden from HtmlElement */
573   public Form onshow(String value) {
574      super.onshow(value);
575      return this;
576   }
577
578   @Override /* Overridden from HtmlElement */
579   public Form onstalled(String value) {
580      super.onstalled(value);
581      return this;
582   }
583
584   @Override /* Overridden from HtmlElement */
585   public Form onsubmit(String value) {
586      super.onsubmit(value);
587      return this;
588   }
589
590   @Override /* Overridden from HtmlElement */
591   public Form onsuspend(String value) {
592      super.onsuspend(value);
593      return this;
594   }
595
596   @Override /* Overridden from HtmlElement */
597   public Form ontimeupdate(String value) {
598      super.ontimeupdate(value);
599      return this;
600   }
601
602   @Override /* Overridden from HtmlElement */
603   public Form ontoggle(String value) {
604      super.ontoggle(value);
605      return this;
606   }
607
608   @Override /* Overridden from HtmlElement */
609   public Form onvolumechange(String value) {
610      super.onvolumechange(value);
611      return this;
612   }
613
614   @Override /* Overridden from HtmlElement */
615   public Form onwaiting(String value) {
616      super.onwaiting(value);
617      return this;
618   }
619
620   @Override /* Overridden from HtmlElement */
621   public Form spellcheck(Object value) {
622      super.spellcheck(value);
623      return this;
624   }
625
626   @Override /* Overridden from HtmlElement */
627   public Form style(String value) {
628      super.style(value);
629      return this;
630   }
631
632   @Override /* Overridden from HtmlElement */
633   public Form tabindex(Object value) {
634      super.tabindex(value);
635      return this;
636   }
637
638   /**
639    * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-fs-target">target</a> attribute.
640    *
641    * <p>
642    * Specifies where to display the response after form submission.
643    *
644    * <p>
645    * Possible values:
646    * <ul>
647    *    <li><js>"_self"</js> - Load in the same frame (default)</li>
648    *    <li><js>"_blank"</js> - Load in a new window or tab</li>
649    *    <li><js>"_parent"</js> - Load in the parent frame</li>
650    *    <li><js>"_top"</js> - Load in the full body of the window</li>
651    *    <li>Frame name - Load in the named frame</li>
652    * </ul>
653    *
654    * @param value Where to display the form submission response.
655    * @return This object.
656    */
657   public Form target(String value) {
658      attr("target", value);
659      return this;
660   }
661
662   @Override /* Overridden from HtmlElement */
663   public Form title(String value) {
664      super.title(value);
665      return this;
666   }
667
668   @Override /* Overridden from HtmlElement */
669   public Form translate(Object value) {
670      super.translate(value);
671      return this;
672   }
673}