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

Form Component #151

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
c7e6576
introduction of a forms component
reusr1 Aug 12, 2020
eec8db3
Added success page and failure message dialog options
qial Aug 13, 2020
e3cb545
Added more options to Form's model
qial Aug 17, 2020
f0b255b
Updated form component with test submit code
qial Aug 17, 2020
289a91e
Updated form to use javascript function correctly and fixed dialog is…
qial Aug 19, 2020
d4dc94d
Fixed failure message coming through
qial Aug 19, 2020
cbfe6d7
Updated submitfunction workings
qial Aug 19, 2020
2bb5e16
Updated submitfunction to correctly handle all forms of functions and…
qial Aug 20, 2020
74bb4e7
Fixed functions inside of objects, but doesn't fail well when the obj…
qial Aug 20, 2020
07ce128
Fixed functions inside nested objects in the submitfunction dialog
qial Aug 20, 2020
77057b8
Changed defaultSubmit to onSubmit, changed function not found alert t…
qial Aug 20, 2020
fd9728f
Fixed some styling issues, cleaned up form dialog with hints
qial Aug 20, 2020
5152f32
Updated onSubmit closure to better format so 'this' is carried over
qial Aug 20, 2020
88ca794
Cleaned up useless cases in the submit function loop
qial Aug 20, 2020
75dcf2f
Updated error messages for bad json in the form field model
qial Aug 20, 2020
0196f01
Added _blank target to form model docs link, and removed inline editi…
qial Aug 20, 2020
9c83f7b
poc style implementation of a data list component and a save/load han…
reusr1 Aug 20, 2020
35849d3
Merge branch 'issues/136' of https://github.com/headwirecom/themeclea…
reusr1 Aug 20, 2020
ce28f34
Updated form samples and added sample-all with all supported inputs
qial Aug 21, 2020
99450b8
Updated sample content to fix jcr import error
qial Aug 21, 2020
4184cc1
#136 added styles to error messages and submit btn
smcgrath0 Aug 24, 2020
ba6e404
Fixed Submit button text and other issues with formatting
qial Aug 24, 2020
77c84f1
#136 added transition for error message
smcgrath0 Aug 24, 2020
6ae0a1c
#136 added submit button in all example schemas and removed in markup
smcgrath0 Aug 24, 2020
b44317b
Merge branch 'issues/136' of https://github.com/headwirecom/themeclea…
smcgrath0 Aug 24, 2020
f247851
#136 added styles for all inputs
smcgrath0 Aug 24, 2020
9c24c09
#136 added button alignment and size dialog/styling
smcgrath0 Aug 24, 2020
3862af1
#136 fixed class string/fixed font on textarea/select
smcgrath0 Aug 25, 2020
e7da0a8
updated inline settings for failure messages
qial Aug 25, 2020
5dac11f
Added groups to the input type sample form
qial Aug 25, 2020
3fb9e95
#136 fixed form alignment issue/group styling/checkbox alignment
smcgrath0 Aug 25, 2020
2e29646
#136 dialog button size: sm,lg -> small, large
smcgrath0 Aug 25, 2020
797f0f0
Merge branch 'issues/136' of https://github.com/headwirecom/themeclea…
smcgrath0 Aug 25, 2020
51c8a9c
#136 removed form error transition
smcgrath0 Sep 4, 2020
fe2c405
Merge remote-tracking branch 'upstream/issues/136' into issues/136
qial Sep 4, 2020
056aa96
#136 removing a final setTimeout on the error message
qial Sep 4, 2020
c53e69d
Merge branch 'develop' of https://github.com/headwirecom/themeclean-f…
smcgrath0 Sep 4, 2020
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
597 changes: 597 additions & 0 deletions core/src/main/java/com/themecleanflex/models/FormModel.java

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions fragments/form/hatch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module.exports = {
convert: function($, f) {
f.wrap($, 'themecleanflex-components-block')
f.bindAttribute($.parent(),'model','model')

const failureP = $.find('p').first()
f.mapField(failureP,'failureText')

const div2 = $.find('div').eq(1)
f.replace(div2, '<vue-form-generator></vue-form-generator>')

const formEl = $.find('form')
f.bindEvent(formEl,'submit.prevent','onSubmit')

const form = $.find('vue-form-generator').first()
f.bindAttribute(form,'model','formModel')
f.bindAttribute(form,'schema','schema')
f.bindAttribute(form,'options','formOptions')

f.bindPath($)
}
}
51 changes: 51 additions & 0 deletions fragments/form/model.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"definitions": {
"Form": {
"type": "object",
"x-type": "component",
"properties": {
"schema": {
"type": "string",
"x-source": "inject",
"x-form-label": "Form Model",
"x-form-type": "textarea",
"x-form-hint": "JSON description passed to vue-form-generator, see <a href='https://vue-generators.gitbook.io/vue-generators/fields'>vue form generator fields documentation</a>",
qial marked this conversation as resolved.
Show resolved Hide resolved
"x-form-max": "16000"
},
qial marked this conversation as resolved.
Show resolved Hide resolved
"endpointurl": {
"type": "string",
"x-source": "inject",
"x-form-label": "Form submit endpoint URL",
"x-form-type": "text",
"x-default": ""
},
"submitfunction": {
"type": "string",
"x-source": "inject",
"x-form-label": "Javascript function to call on submit",
"x-form-hint": "Function must accept (model, formdata)",
"x-form-type": "text",
"x-default": "onSubmit"
},
"failmessage": {
"type": "string",
"x-source": "inject",
"x-form-label": "Failure Message",
"x-form-type": "text",
"x-default": "Error processing form"
},
"successpage": {
"type": "string",
"x-source": "inject",
"x-form-type": "pathbrowser",
"x-form-label": "Submit Success Page",
"x-form-browserRoot": "/content/themecleanflex/pages"
},
"bgref": {
"$ref": "fragments/block/model.json#/definitions/Block",
"x-form-type": "reference"
}
}
}
}
}
7 changes: 7 additions & 0 deletions fragments/form/sample-contact.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"title": "Form - Contact",
"group": "Features",
"model": {
"schema": "{}"
qial marked this conversation as resolved.
Show resolved Hide resolved
}
}
7 changes: 7 additions & 0 deletions fragments/form/sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"title": "Form",
"group": "Features",
"model": {
"schema": "{}"
qial marked this conversation as resolved.
Show resolved Hide resolved
}
}
9 changes: 9 additions & 0 deletions fragments/form/template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div>
<div>
<p></p>
</div>
<form>
<div></div>
<input type="submit">
</form>
</div>
75 changes: 75 additions & 0 deletions fragments/form/template.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<template>
<themecleanflex-components-block v-bind:model="model">
<div v-bind:data-per-path="model.path">
<div>
<p data-per-inline="failureText">{{failureText}}</p>
</div>
<form v-on:submit.prevent="onSubmit">
<vue-form-generator v-bind:model="formModel" v-bind:schema="schema" v-bind:options="formOptions"></vue-form-generator>
<input type="submit">
</form>
</div>
</themecleanflex-components-block>
</template>

<script>
export default {
props: ['model'],
data() {
return {
formModel: {},
formOptions: {
validateAfterChange: true
},
failureText: ''
}
},
methods: {
onSubmit(e) {
if(this.model.submitfunction != 'onSubmit' && this.model.submitfunction != '') {
const objs = this.model.submitfunction.split('.')
let parent = window
let i = 0
while(i < objs.length && parent[objs[i]]) {
if(i == objs.length-1) {
try {
const result = parent[objs[i]](this.model,this.formModel)
if(result === false) {
this.failureText = this.model.failmessage
}
} catch(err) {
console.error(err)
this.failureText = this.model.failmessage
}
return
}
parent = parent[objs[i]]
i++
}
console.log('window.' + this.model.submitfunction + ' not found')
this.failureText = this.model.failmessage
return
}
axios.post(this.model.endpointurl, {
form: this.formModel
})
.then( (response) => {
$peregrineApp.loadContent(this.model.successpage)
})
.catch( (error) => {
this.failureText = this.model.failmessage
})
}
},
computed: {
schema() {
try {
return JSON.parse(this.model.schema)
} catch( error ) {
return { fields: [] }
}
}
}
}
</script>

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" jcr:primaryType="per:Component" jcr:title="Form">
<jcr:content jcr:primaryType="nt:unstructured" __variations="true">
<sample jcr:primaryType="nt:unstructured" title="Form" group="Features">
<jcr:content jcr:primaryType="nt:unstructured" schema="{}"/>
</sample>
<sample-contact jcr:primaryType="nt:unstructured" title="Form - Contact" group="Features">
<jcr:content jcr:primaryType="nt:unstructured" schema="{}"/>
</sample-contact>
</jcr:content>
</jcr:root>
Loading