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 org.apache.juneau.marshall.*; 020 021/** 022 * DTO for an HTML <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#the-optgroup-element"><optgroup></a> 023 * element. 024 * 025 * <p> 026 * The optgroup element represents a group of option elements within a select element. It provides 027 * a way to organize related options into logical groups, making it easier for users to find and 028 * select the desired option. The label attribute provides the group heading. 029 * 030 * <h2 class='section'>Examples:</h2> 031 * <p class='bcode w800'> 032 * <jk>import static</jk> org.apache.juneau.bean.html5.HtmlBuilder.*; 033 * 034 * <jc>// Simple option group</jc> 035 * Optgroup <jv>optgroup1</jv> = <jsm>optgroup</jsm>(<js>"Fruits"</js>, 036 * <jsm>option</jsm>(<js>"apple"</js>, <js>"Apple"</js>), 037 * <jsm>option</jsm>(<js>"banana"</js>, <js>"Banana"</js>), 038 * <jsm>option</jsm>(<js>"orange"</js>, <js>"Orange"</js>) 039 * ); 040 * 041 * <jc>// Disabled option group</jc> 042 * Optgroup <jv>optgroup2</jv> = <jsm>optgroup</jsm>(<js>"Vegetables"</js>, 043 * <jsm>option</jsm>(<js>"carrot"</js>, <js>"Carrot"</js>), 044 * <jsm>option</jsm>(<js>"broccoli"</js>, <js>"Broccoli"</js>) 045 * ).disabled(<jk>true</jk>); 046 * 047 * <jc>// Multiple option groups in a select</jc> 048 * Select <jv>select1</jv> = <jsm>select</jsm>(<js>"food"</js>, 049 * <jsm>optgroup</jsm>(<js>"Fruits"</js>, 050 * <jsm>option</jsm>(<js>"apple"</js>, <js>"Apple"</js>), 051 * <jsm>option</jsm>(<js>"banana"</js>, <js>"Banana"</js>) 052 * ), 053 * <jsm>optgroup</jsm>(<js>"Vegetables"</js>, 054 * <jsm>option</jsm>(<js>"carrot"</js>, <js>"Carrot"</js>), 055 * <jsm>option</jsm>(<js>"broccoli"</js>, <js>"Broccoli"</js>) 056 * ) 057 * ); 058 * </p> 059 * 060 * <p> 061 * The following convenience methods are provided for constructing instances of this bean: 062 * <ul class='javatree'> 063 * <li class='jc'>{@link HtmlBuilder} 064 * <ul class='javatree'> 065 * <li class='jm'>{@link HtmlBuilder#optgroup() optgroup()} 066 * <li class='jm'>{@link HtmlBuilder#optgroup(Object...) optgroup(Object...)} 067 * </ul> 068 * </ul> 069 * 070 * <h2 class='section'>See Also:</h2><ul> 071 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanHtml5">juneau-bean-html5</a> 072 * </ul> 073 */ 074@Marshalled(typeName = "optgroup") 075public class Optgroup extends HtmlElementContainer<Optgroup> { 076 077 /** 078 * Creates an empty {@link Optgroup} element. 079 */ 080 public Optgroup() {} 081 082 /** 083 * Creates an {@link Optgroup} element with the specified child nodes. 084 * 085 * @param children The child nodes. Must not be <jk>null</jk>. 086 */ 087 public Optgroup(Object...children) { 088 children(children); 089 } 090 091 /** 092 * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-optgroup-disabled">disabled</a> attribute. 093 * 094 * <p> 095 * Whether the form control is disabled. 096 * 097 * <p> 098 * This attribute uses deminimized values: 099 * <ul> 100 * <li><jk>false</jk> - Attribute is not added</li> 101 * <li><jk>true</jk> - Attribute is added as <js>"disabled"</js></li> 102 * <li>Other values - Passed through as-is</li> 103 * </ul> 104 * 105 * @param value 106 * The new value for this attribute. 107 * Typically a {@link Boolean} or {@link String}. 108 * Can be <jk>null</jk> to unset the attribute. 109 * @return This object. 110 */ 111 public Optgroup disabled(Object value) { 112 attr("disabled", deminimize(value, "disabled")); 113 return this; 114 } 115 116 /** 117 * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-optgroup-label">label</a> attribute. 118 * 119 * <p> 120 * Specifies the user-visible label for the option group. This label is displayed 121 * in the select element to group related options together. 122 * 123 * <p> 124 * The label should be descriptive and help users understand the grouping of options. 125 * 126 * @param value The user-visible label for the option group. Can be <jk>null</jk> to unset the attribute. 127 * @return This object. 128 */ 129 public Optgroup label(String value) { 130 attr("label", value); 131 return this; 132 } 133 134}