Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIO-7773: Adding floating labels to Bootstrap 5 template. #5468

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 130 additions & 0 deletions app/examples/floating.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
---
title: Floating Labels
layout: vtabs
section: examples
formioFull: true
weight: 31
---
With the default template of Bootstrap 5, it is now possible to have Floating Labels feature where the labels are placeholders until the user clicks into component. The label, will then move to above the cursor improving the UI/UX of the form experience. To enable floating labels, you must first use the "default" Bootstrap 5 template, and then provide the following when embedding your form.

```js
Formio.createForm(document.getElementById('formio'), {...}, {
floatingLabels: true
});
```

Here is an example.

```html
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons/font/bootstrap-icons.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap/dist/css/bootstrap.min.css">
<script src="https://cdn.form.io/js/formio.embed.js"></script>
<div id="formio"></div>
```

<div class="row">
<div class="col col-sm-6">

<pre>
Formio.createForm(document.getElementById('formio'), {
components: [
{
type: 'textfield',
key: 'firstName',
label: 'First Name',
placeholder: 'Enter your first name.',
input: true,
validate: {
required: true
}
},
{
type: 'textfield',
key: 'lastName',
label: 'Last Name',
placeholder: 'Enter your last name',
input: true,
validate: {
required: true
}
},
{
type: 'email',
key: 'email',
label: 'Email',
placeholder: 'Enter your email',
input: true,
validateOn: 'blur'
},
{
type: 'button',
action: 'submit',
label: 'Submit',
theme: 'primary'
}
]
}, {
floatingLabels: true
});
</pre>

</div>
<div class="col col-sm-6">
<h3>Result</h3>
<div class="card card-body bg-light">
<div id="formio"></div>
<script type="text/javascript">
Formio.createForm(document.getElementById('formio'), {
components: [
{
type: 'textfield',
key: 'firstName',
label: 'First Name',
placeholder: 'Enter your first name.',
input: true,
validate: {
required: true
}
},
{
type: 'textfield',
key: 'lastName',
label: 'Last Name',
placeholder: 'Enter your last name',
input: true,
validate: {
required: true
}
},
{
type: 'email',
key: 'email',
label: 'Email',
placeholder: 'Enter your email',
input: true,
validateOn: 'blur'
},
{
type: 'button',
action: 'submit',
label: 'Submit',
theme: 'primary'
}
]
}, {
floatingLabels: true
}).then(function(form) {
form.on('change', function(changed) {
console.log('Changed!', changed);
});

form.on('submit', function(submission) {
console.log('Submitted!', submission);
});
});
</script>
</div>
</div>
</div>


1 change: 1 addition & 0 deletions src/Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ export default class Element {
token: Formio.getToken({
decode: true
}),
options: this.options,
config: this.root && this.root.form && this.root.form.config
? this.root.form.config
: this.options?.formConfig
Expand Down
1 change: 1 addition & 0 deletions src/components/_classes/component/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,7 @@ export default class Component extends Element {
return !this.component.label ||
((!this.isInDataGrid && this.component.hideLabel) ||
(this.isInDataGrid && !this.component.dataGridLabel) ||
this.options.floatingLabels ||
this.options.inputsOnly) && !this.builderMode;
}

Expand Down
1 change: 1 addition & 0 deletions types/formio.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class Formio {
static namespace: string;
static formOnly?: boolean;
static rulesEntities: any;
static options: any;
delete(type: any, opts?: any): any;
index(type: any, query?: any, opts?: any): any;
save(type: any, data: any, opts?: any): any;
Expand Down
Loading