App
2sxc Custom Input Fields (11.02+)
2sxc 11 makes it very easy to create custom input fields using standard WebComponents. This example shows the most basic case - just a dummy message (so not a real input field).
You can use it to learn about things like:
- Naming conventions for where to put the files
- Naming conventions for the tagName
- Using customElements.define(...)to register your element
- How web components use constructor()and making sure you have thesuper()call there
- Using connectedCallback()anddisconnectedCallback()to init/destroy your component
So just have a look and discover how simple everything can be 🚀.
Edit for Anonymous Enabled for Tutorial
Important: We opened permissions that you can experience the edit dialog - so you can save, but it will just create draft data 😉.
This example shows a dummy-field which doesn't allow editing, but will just show a message.
⬇️ Result | Source ➡️
Hit this edit button to have a look:
2sxc 11 makes it very easy to create custom input fields using standard WebComponents. This example shows a color picker using Pickr, a cool JS library.
⬇️ Result | Source ➡️
  This example shows a real string-field uses Pickr to provide a color picker. 
  Hit this edit button to have a look:
You can learn how to:
- Use connector.loadScript(...)to load a js library
- Use connector.datato get thevalueand update it
- How to only update the data if you really change it (so users can cancel the dialog without being asked)
- How to save nullto explicitly not save or reset a value
- Use disconnectedCallback()to destroy inner objects
Input fields may expect some configuration - like default colors or WebApi endpoints. To enable such a configuration, we need a Content-Type which defines all the fields that can be configured. This can be in the app-data, or it can be stored in a subfolder of the field-extension, to make redestribution easier.
⬇️ Result | Source ➡️
  This example shows two color-picker fields, with different initial configurations. 
  Hit this edit button to have a look: 
This example contains the json-exported content-type in the folder /system/field-string-app-color-pickr-pro/.data/contenttypes/ so you could just copy the extension folder to another app and use it from there.
So in this tutorial you'll learn how to:
- To see how the UI changes based on field configuration
- How to access such pre-configured settings with connector.field.settings
- The Content-Type for configuration is included in the extension folder
Creating an own WYSIWYG would be super difficult. This is why we decided to create a simple API where you can use the existing WYSIWYG and just reconfigure it. For the configuration you will need to understand the TinyMCE API and the names of our callbacks, but then it's really easy.
⬇️ Result | Source ➡️
  This example shows a reduced WYSIWYG with only 4 buttons. 
  Hit this edit button to have a look: 
You can learn how to:
- Use connector.loadScript(...)to load the builtin WYSIWYG
- ...and wait for the callback to ensure it's ready
- Create a inner field-string-wysiwyg
- Set the mode to edit(instead ofpreview)
- Attach the connectorso the inner object has it as well
- Attach the reconfigureobject
- Create your own Reconfiguratorwhich can make changes
- Use configureOptionsto set a different toolbar
This example show how we customize more of TinyMCE.
⬇️ Result | Source ➡️
  This example keeps the default buttons and adds another one, with multi-language labels 
  Hit this edit button to have a look: 
You can learn how to:
- Use addTranslations()
- Use configureOptions(...)to extend the toolbar
- Use configureAddOns to change button options for the image
- Run code when the editor is running initto add button definitions
