Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

134
Views
Is it possible to preset the type of a new selection in the jQuery FormBuilder?

I use the nice FormBuilder from Kevin Chappell

https://formbuilder.online/docs/

Several types can be defined for the 'text' field. I have integrated the new control 'time'. I now want if this new control is clicked, 'time' should be preset in the 'Type' field.

How can i adjust that?

PS: The code example does not run here but only locally (sessionStorage topic)

jQuery(function($) {
  var fbTemplate = document.getElementById('fb-editor');
  var options = {
    fields : [{
        label: 'Time',
        attrs: {
            type: 'text'
        },
        icon: '๐Ÿ•‘'
    }],
    subtypes: {
      text: ['datetime-local','time']
    },
    disabledSubtypes: {
        text: ['password','email','color','tel'],
    }
  };
  $(fbTemplate).formBuilder(options);
});
body {
  background: lightgrey;
  font-family: sans-serif;
}
<!DOCTYPE html>
<html lang="en" >
<head>
  <meta charset="UTF-8">
  <title>CodePen - formBuilder: Options -&gt; subtypes</title>
  <link rel="stylesheet" href="./style.css">

</head>
<body>
<!-- partial:index.partial.html -->
<div id="fb-editor"></div>
<!-- partial -->
  <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js'></script>
<script src='https://formbuilder.online/assets/js/form-builder.min.js'></script><script  src="./script.js"></script>

</body>
</html>

about 4 years ago ยท Juan Pablo Isaza
1 answers
Answer question

0

I didn't find out, but i took a different path for it. :-)

Enter the new element as type time in the field definition. A new subtype time has also been defined.

Then add the time in the controls register.

jQuery(function($) {
  var fbTemplate = document.getElementById('fb-editor');
  var options = {
    fields : [{
      label: 'Time',
      attrs: {
        type: 'time'
      },
      icon: '๐Ÿ•‘'
    }],
    subtypes: {
      time: ['time']
    }
  };
  $(fbTemplate).formBuilder(options);
});

// src/js/control/text.js
// register this control for the following types & text subtypes
control.register(['text', 'file', 'date', 'number', 'time'], controlText)
control.register(['text', 'password', 'email', 'color', 'tel'], controlText, 'text')
body {
  background: lightgrey;
  font-family: sans-serif;
}
<!DOCTYPE html>
<html lang="en" >
<head>
  <meta charset="UTF-8">
  <title>formBuilder</title>
  <link rel="stylesheet" href="./style.css">

</head>
<body>

<div id="fb-editor"></div>

<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js'></script>
<script src='https://formbuilder.online/assets/js/form-builder.min.js'></script>
<script  src="./script.js"></script>

</body>
</html>

about 4 years ago ยท Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!