Skip to content

Form builder update fields 4768 #219

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions js/interface.templates.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 8 additions & 9 deletions js/libs/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,17 @@ var app = new Vue({

$(event.item).remove();

var i = (_.max(_.compact(_.map(this.fields, function (field) {
var idx = field.name.match(/^field-([0-9]+)/);
if (idx && idx.length) {
return parseInt(idx[1], 10);
}
}))) || 0) + 1;
var fieldsWithSameName = _.filter(this.fields, function(item) {
return item.name.match(component.name.replace('(', '\\(').replace(')', '\\)'));
});

var index = fieldsWithSameName.length;

this.fields.splice(event.newIndex, 0, {
return this.fields.splice(event.newIndex, 0, {
_type: componentName,
_submit: typeof component.submit !== 'undefined' ? component.submit : true,
name: 'field-' + i,
label: component.name,
name: component.name + (index ? '-' + index : ''),
label: component.name + (index ? '-' + index : ''),
value: value.default || value.type()
});
}
Expand Down
29 changes: 13 additions & 16 deletions js/libs/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,7 @@ Fliplet.FormBuilder = (function() {

// On submit event
component.methods._onSubmit = function() {
if (this.name === '') {
this.name = this.label;
}

if (this._fieldNameError) {
if (this._fieldNameError || this._fieldLabelError) {
return;
}

Expand All @@ -183,13 +179,6 @@ Fliplet.FormBuilder = (function() {
component.methods.onSubmit = component.methods._onSubmit;
}

if (!component.mounted) {
component.mounted = function() {
this._showNameField = this.name !== this.label;
this.initTooltip();
};
}

component.props._fields = {
type: Array
};
Expand Down Expand Up @@ -227,29 +216,37 @@ Fliplet.FormBuilder = (function() {

component.computed._fieldLabelError = function() {
if (!this.label) {
return 'Please provide a Field name & label';
return 'Please provide a Field Label';
}

var existing = _.findIndex(this._fields, {
name: this.name
});

if (existing > -1 && existing !== this._idx) {
return this.name + ' is taken. Please use another Field Name.';
return this.name + ' is taken. Please use another Field Label.';
}

return '';
};

component.methods._addCustomName = function() {
this._showNameField = !this._showNameField;
this.name = this.label;
this.initTooltip();
};

if (!component.methods.addCustomName) {
component.methods.addCustomName = component.methods._addCustomName;
}

component.methods._compareFieldName = function() {
this.name = this.label;
this.initTooltip();
};

if (!component.methods.compareFieldName) {
component.methods.compareFieldName = component.methods._compareFieldName;
}

component.methods._initTooltip = function() {
var $vm = this;
Expand Down
31 changes: 13 additions & 18 deletions templates/configurations/form.interface.hbs
Original file line number Diff line number Diff line change
@@ -1,40 +1,35 @@
<form v-on:submit.prevent="onSubmit" class="form-horizontal">
<div class="form-fields-holder">
<div v-if="_isFormField">
<div class="form-group cleafix" :class="{ 'has-error': _fieldLabelError && !_showNameField }">
<div class="form-group cleafix" :class="{ 'has-error': _fieldLabelError }">
<div class="col-xs-12">
<div class="row">
<div class="col-xs-5">
<label class="control-label" for="field-label" v-if="!_showNameField">
Field name & label</label>
<label class="control-label" for="field-label" v-else>
Field label</label>
</div>
<div class="col-xs-7 text-right" v-if="!_showNameField">
<span class="btn-link form-fields-customize" @click="addCustomName">Customize field name <i class="text-muted fa fa-question-circle" ref="tooltip" data-viewport=".modal-body" data-toggle="tooltip" data-placement="left" title="Customize a different field name for the data source"></i>
</span>
<label class="control-label" for="field-label">Field label</label>
</div>
<div class="col-xs-12">
<input class="form-control" id="field-label" type="text" v-model.trim="label" placeholder="Field description" />
<p class="help-block" v-if="_fieldLabelError && !_showNameField" v-html="_fieldLabelError"></p>
<p class="help-block" v-if="_fieldLabelError" v-html="_fieldLabelError"></p>
</div>
</div>
</div>
</div>

<div class="form-group cleafix" :class="{ 'has-error': _fieldNameError }" v-if="_showNameField">
<div class="form-group cleafix" :class="{ 'has-error': _fieldNameError }">
<div class="col-xs-12">
<div class="row">
<div class="col-xs-6">
<div class="col-xs-5">
<label class="control-label" for="field-name">Field name</label>
</div>
<div class="col-xs-6 col-xs-6 text-right">
<span class="btn-link form-fields-customize" @click="addCustomName">
Auto-match with field label
</span>
<div class="col-xs-7 text-right" v-if="!_showNameField">
<span class="btn-link form-fields-customize" @click="addCustomName">Customize field name <i class="text-muted fa fa-question-circle" ref="tooltip" data-viewport=".modal-body" data-toggle="tooltip" data-placement="left" title="Customize a different field name for the data source"></i></span>
</div>
<div class="col-xs-7 col-xs-7 text-right" v-else>
<span class="btn-link form-fields-customize" @click="compareFieldName">Auto-match with field label</span>
</div>
<div class="col-xs-12">
<input id="field-name" class="form-control" type="text" v-model.trim="name" placeholder="Field name" />
<p v-if="!_showNameField">\{{name}}</p>
<input v-else id="field-name" class="form-control" type="text" v-model.trim="name" placeholder="Field name" />
<p class="help-block" v-if="_fieldNameError" v-html="_fieldNameError"></p>
</div>
</div>
Expand Down Expand Up @@ -80,6 +75,6 @@
</div>

<div class="footer">
<button type="submit" class="btn btn-primary" :class="{ disabled: (_fieldNameError && _showNameField) || (_fieldLabelError && !_showNameField) }">Done</button>
<button type="submit" class="btn btn-primary" :class="{ disabled: _fieldNameError || _fieldLabelError }">Done</button>
</div>
</form>