UNPKG

appblocks

Version:

A lightweight javascript library for building micro apps for the front-end.

58 lines (55 loc) 2.25 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Attibute Filters test</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous"> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script> </head> <body> <style> .red { background-color: red; color: white; } .green { background-color: green; color: white; } </style> <div id="app"></div> <template id="appTemplate"> <div c-for="field in data.fields"> <label for="inp-{field.fieldName}">{field.label}</label> <input type="{field.type}" id="inp-{field.fieldName}" class="{field.isValid|validationClass}" name="{field.fieldName}" value="{field.value}"> </div> </template> <script src="../dist/appblocks.umd.js"></script> <script> var app = new AppBlock({ name: "RenderApp", el: document.getElementById('app'), template: document.getElementById('appTemplate'), renderEngine: 'Idiomorph', data: { fields: [ {fieldName: "name", type: "text", isValid: true, label: "This shoud be green", value: "Joe"}, {fieldName: "email", type: "email", isValid: false, label: "This should be red", value: "joe@example.com"} ] }, filters: { validationClass(app, value) { console.log(value); if (value === true) { return "green"; } else { return "red"; } } } }); </script> </body> </html>