repl.it
@cmarmar/

custom field attempt

HTML, CSS, JS

No description

fork
loading
Files
  • index.html
  • script.js
  • style.css
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://www.contentstack.com/sdks/contentstack-ui-extensions/dist/latest/ui-extension-sdk.js"></script>
    <link href="https://www.contentstack.com/sdks/contentstack-ui-extensions/dist/latest/ui-extension-sdk.css" rel="stylesheet" type="text/css" media="all">
  </head>
  <body>
    <input type="text" id="custom-text-input" onchange="textChange()">
    <script type="text/javascript"> 
      window.extensionField = {} //initialize field extension
      let customTextInput = document.getElementById("custom-text-input") //find text input element
      ContentstackUIExtension.init().then((extension)=>{
        extensionField = extension //making extension object globally available
        customTextInput.value = extensionField.getData() //get current text input value from Contentstack and update the input element
      })
      const textChange = () => { //on text change event, pass new text value to Contentstack
        extensionField.field.setData(customTextInput.value) 
      }
    </script>
  </body>
</html>
result
console