-2

How can I make the select form required? I tried putting "required" but it doesn't work.

<div class="form-group">
    <label for="sel2">How many years have you been trading *</label>
    <select  class="form-control" id="sel2" required>
        <option>Please select one</option>
        <option>Start Up</option>
        <option value="1-2">1-3</option>
        <option value="3-4">3-4</option>
        <option value="5more">5 or more</option>
     </select>
</div>

Also for this one, I just got this from a website and I downloaded the zip file but I need to add a required attribute

<div class="form-group">
    <label>Country *</label><br>
    <div id="basic" data-input-name="country" required></div>
</div>


 <script>
$('#basic').flagStrap();

$('#origin').flagStrap({
    placeholder: {
        value: "",
        text: "Country of origin"
    }
});

$('#options').flagStrap({
    countries: {
        "AU": "Australia",
        "GB": "United Kingdom",
        "US": "United States"
    },
    buttonSize: "btn-sm",
    buttonType: "btn-info",
    labelMargin: "10px",
    scrollable: false,
    scrollableHeight: "350px"
});

$('#advanced').flagStrap({
    buttonSize: "btn-lg",
    buttonType: "btn-primary",
    labelMargin: "20px",
    scrollable: false,
    scrollableHeight: "350px",
    onSelect: function (value, element) {
        alert(value);
        console.log(element);
    }
});
</script>
Nnn
  • 69
  • 4
  • 12

1 Answers1

2

Required is not woking here because you have not set valued in all option.Set values in first two options:

<link href="view/css/flags.css" rel="stylesheet">

<select  class="form-control" id="sel2" required>
       <option value="">Please select one</option>
       <option  value="startup">Start Up</option>
       <option value="1-2">1-3</option>
       <option value="3-4">3-4</option>
       <option value="5more">5 or more</option>
 </select>

<script>
$('#basic').flagStrap();

$('#origin').flagStrap({
    placeholder: {
        value: "",
        text: "Country of origin"
    }
});

$('#options').flagStrap({
    countries: {
        "AU": "Australia",
        "GB": "United Kingdom",
        "US": "United States"
    },
    buttonSize: "btn-sm",
    buttonType: "btn-info",
    labelMargin: "10px",
    scrollable: false,
    scrollableHeight: "350px"
});

$('#advanced').flagStrap({
    buttonSize: "btn-lg",
    buttonType: "btn-primary",
    labelMargin: "20px",
    scrollable: false,
    scrollableHeight: "350px",
    onSelect: function (value, element) {
        alert(value);
        console.log(element);
    }
});
</script>
Nnn
  • 69
  • 4
  • 12
Dhara Parmar
  • 8,021
  • 1
  • 16
  • 27