Store a value from input element and pass it on a json object using ractive

I’m currently trying to learn ractive js at the moment. Right now I’m figuring how I can store a dynamic value and pass it on a JSON object and set it to the API.

I have managed to get the value using app.get but how I do store it or pass it to a specific key-pair or object. Right now I’m getting an unexpected identifier as an error.

WIP: http://fiddle.jshell.net/clestcruz/6L1vwcqw/

<div class="form-element-container">
    <label>Company Name <span class="required">*</span></label>
    <input type="text" class="form-text full-width" placeholder="Enter the company name" id="accountName" value="{{leadData.accountName}}"/>
</div>

<div class="col col2">
    <label>Street Name.</label>
    <input type="text" class="form-text" placeholder="-" id="streetName" value="{{leadData.streetName}}"/>
</div>

<div class="form-element-container default-cta-container">
    <a class="button cta" on-click="addLead">Create Account</a>
</div>
        app.on('addLead', function(event) {
          var leadData     = {}, 
          var data         = ractive.get('leadData');

           app.set(function(data, data) {
                var leadData     = {
                    "accountName": data.accountName,
                    "streetName" : data.streetName,
                }
            });

        });

There are two problems with your code.

First, you have a comma instead of a semicolon after this line:

var leadData     = {},  // <-- this should be a semicolon
var data         = ractive.get('leadData');

And second, app.set() needs to be called with a string specifying which property you’re setting, and the data as the second argument:

ractive.set('leadData', {
  "accountName": data.accountName,
  "streetName" : data.streetName,
});

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.