Skip to content

Commit

Permalink
Merge pull request #1 from ems-project/submissions
Browse files Browse the repository at this point in the history
integrate submission bundle
fix javascript validations
  • Loading branch information
dameert authored May 2, 2019
2 parents 8e1138b + 2f7c5e9 commit ada7f4c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Controller/FormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ public function getForm(Request $request, string $domainId, string $formId)

if ($form->isValid()) {
return $this->forward('EMS\SubmissionBundle\Controller\SubmissionController::submit', [
'submissionId' => $formId,
'submissionId' => sprintf('%s-%s', $domainId, $formId),
'data' => $form->getData(),
'locale' => $request->getLocale(),
]);
}

Expand Down
9 changes: 9 additions & 0 deletions Resources/assets/FormValidations/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

/**
* 1. In your webpack.config.js, create an alias with :
* config.resolve.alias.emsf = path.resolve(__dirname, 'PATH_TO_THIS_FILE');
* 2. In your app.js add : import {} from 'emsf';
* 3. Create the minified files with yarn or webpack
*/
import setNissInszValidation from './js/nissValidation';
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
window.setNissInszValidation = function(nissId) {

export default function setNissInszValidation(nissId) {
let niss = document.getElementById(nissId);

niss.addEventListener('change', function() {
Expand Down
30 changes: 26 additions & 4 deletions Resources/doc/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,38 @@ Browser side validation

Custom validations
---
Customized validations are available in the js file `form-validations.js`, to expose this file using Webpack,
Customized validations are available in the js file `nissValidation.js`, to expose this file using Webpack,
add the following to your webpack.config.js

```javascript
var config = Encore.getWebpackConfig();
config.resolve.alias.emsf = path.resolve(__dirname, 'vendor/elasticms/form-bundle/Resources/assets/form-validations.js');
let config = Encore.getWebpackConfig();
config.resolve.alias.emsf = path.resolve(__dirname, 'vendor/elasticms/form-bundle/Resources/assets/nissValidation.js');
```

To expose the frontend validations to other applications, create a new javascript file and import the validation functionalities
```javascript
// src/assets/form-validations.js
// src/assets/nissValidation.js
import {} from 'emsf';
```

Using webpack with multiple configurations (https://symfony.com/doc/current/frontend/encore/advanced-config.html) one could use the following configuration:
```javascript
Encore.reset();
Encore
.setOutputPath('public/emsform')
.setPublicPath('/emsform')
.setManifestKeyPrefix('emsform')
.enableSourceMaps(!Encore.isProduction())
.addEntry('js/form-validations', './assets/js/form-validations.js')
;
let formConfig = Encore.getWebpackConfig();
formConfig.resolve.alias.emsf = path.resolve(__dirname, 'vendor/elasticms/form-bundle/Resources/FormValidation/assets/app.js');
formConfig.name = 'formConfig';
module.exports = [config, formConfig];
```
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"require" : {
"php" : ">=7.1",
"elasticms/client-helper-bundle" : "^3.0",
"elasticms/submission-bundle" : "~0.0.1",
"twig/twig" : "^2.4",
"symfony/form": "~4.1.0",
"symfony/routing": "~4.1.0",
Expand Down

0 comments on commit ada7f4c

Please sign in to comment.