Picture of Jason Chui
Get the value of textbox in designer view and store it as global variable in .js
by Jason Chui - Thursday, 24 January 2019, 3:25 AM
 

I want to retrieve value from a custom textbox.

i added this line of code in , so to get a new textbox in designer view

I am new adapt learning, so is there anyway i can retrieve the value key in this textbox and set it as a global variable in adapt-textConfirmation.js ?

Picture of Matt Leathes
Re: Get the value of textbox in designer view and store it as global variable in .js
by Matt Leathes - Thursday, 24 January 2019, 10:43 AM
 

If set, it'll be made available to the model for that component.

Without being able to see the code in adapt-textConfirmation.js it's a bit tricky to advise for sure but I suspect you'll be able to reference it from in there by doing something like this.model.get('Database')

Equally you might find it better to add something like this to the 'globals' section of that properties.schema (alongside the ariaRegion entry), then you'll be able to reference it from anywhere in the Adapt code by doing Adapt.course.get('_globals')._components._textConfirmation.Database - have a look at how popupPagination is set in the hot graphic component for an example.

Picture of Matt Leathes
Re: Get the value of textbox in designer view and store it as global variable in .js
by Matt Leathes - Thursday, 24 January 2019, 11:51 AM
 

Sorry just to clarify, if you put it in the 'globals' section that means the author will only have/be able to set this value once for the entire course - as opposed to how you've currently got it set up where it will need to be set for every single component instance.

Picture of Jason Chui
Re: Get the value of textbox in designer view and store it as global variable in .js
by Jason Chui - Friday, 25 January 2019, 2:21 AM
 

Hello , thank for asking. However i am only tasked to modify the code for the plugin instead of the 'global section' , but is there anyway to put it in the 'globals' section just by modifying the code in the plugin ?

var TextConfirmation = ComponentView.extend({
events: {
'click [type="checkbox"]': 'onConfirmation',
'keyup .component-item input':'onKeyPress'
//This is new Code
}
 
onKeyPress: function(event) {
if (event.which !== 13) return;
//<ENTER> keypress
this.getDatabaselink(event);
//This is new Method
}
 
getDatabaselink: function() {
datalink = Adapt.course.get('_globals')._components._textConfirmation.Database
console.log("datalink "+ datalink)
//This is a new Method
}
 
I have created these few functions in order to retrieve the value from the text confirmation, however its is not calling when i pressed enter? is there anyway that i can call this function
 
datalink = Adapt.course.get('_globals')._components._textConfirmation.Database
 
Does this method retrieve just the string from textconfirmation ? or it retrieve the whole textconfirmation
Picture of Matt Leathes
Re: Get the value of textbox in designer view and store it as global variable in .js
by Matt Leathes - Friday, 25 January 2019, 10:35 AM
 

Assuming the course author has actually set the value of _components._textConfirmation.Database (either via the authoring tool or manually via course.json if using the framework) then Adapt.course.get('_globals')._components._textConfirmation.Database should contain the value they entered.

I would recommend you use the developer tools to do a bit of exploration... if you execute var Adapt = require('core/js/adapt'); in the Console you will then be able to run Adapt.course.get('_globals')._components in the console to have a proper look around.

Equally you can use the debugger to add a breakpoint in your text confirmation component, allowing you to explore that in more detail.

I recommend you do all this in the framework - it's a lot easier getting new functionality like this working in there first. Once that's done, upload the plugin to the authoring tool and check it works there.