This set of Javascript Multiple Choice Questions & Answers (MCQs) focuses on “Crafting the Public API”.
1. What is necessary when we need to create a new field in craft?
a) Type of the input
b) Type of the output
c) Type of the field
d) Type of argument
View Answer
Explanation: Whenever someone creates a new field in Craft, they must specify what type of field it is. They are organized into Field Groups for convenience, but Field Groups have very little relevance anywhere else in the system.
2. What does the getInputHtml() return?
a) Input
b) Fieldtype’s input HTML
c) Array
d) Value
View Answer
Explanation: The method getInputHtml() returns a fieldtype’s input HTML. It accepts two arguments: $name and $value.
3. How many arguments does the getInputHtml() accept?
a) 1
b) 2
c) 3
d) 4
View Answer
Explanation: The method getInputHtml() returns a fieldtype’s input HTML. The method getInputHtml(0 accepts two arguments: $name and $value. $name is the name you should assign your HTML input name= attribute, and $value is the field’s current value (either from the DB, or the POST data if there was a validation error).
4. Which is the method used to process on the input post data before it is saved to the database?
a) prep()
b) settings()
c) defineSettings()
d) prepSettings()
View Answer
Explanation: defineSettings() method returns an array whose keys define the setting names, and values define the parameters (the type of value, etc). If you need to do any processing on your settings’ post data before they’re saved to the database’s content table, you can do it with the prepSettings() method.
5. What is the purpose of the parameter $name ?
a) Document Name
b) Input Name
c) Output Name
d) ID
View Answer
Explanation: getinputhtml() accepts two arguments: $name and $value. The parameter $name is the name you should assign your HTML input name= attribute.
6. What does the method defineSettings() return?
a) Array of settings name
b) Array of hash key
c) Array of strings
d) Array of objects
View Answer
Explanation: The defineSettings() method returns an array whose keys define the setting names, and values define the parameters (the type of value, etc). If you need to do any processing on your settings’ post data before they’re saved to the database’s content table, you can do it with the prepSettings() method.
7. What is the purpose of the parameter $value?
a) Field’s expected value
b) Field’s previous value
c) Field’s current value
d) Field’s probability value
View Answer
Explanation: getinputhtml() accepts two arguments: $name and $value. The parameter $value is the field’s current value (either from the DB, or the POST data if there was a validation error).
8. When does the defineContentAttribute() method return a false?
a) Data stored in different table
b) Data stored in its own table
c) Data is not stored at all
d) Data is not obtained
View Answer
Explanation: If your fieldtype is storing data in its own table, and doesn’t have any use for a column within the main content table, you may also set defineContentAttribute() to return false. By default, BaseFieldType sets the column to VARCHAR(255), but you can override that with defineContentAttribute().
9. How many events does the BaseFieldType provide?
a) 1
b) 2
c) 3
d) 4
View Answer
Explanation: BaseFieldType provides three events that you can latch code onto:
- onBeforeSave() : Called right before a field is saved.
- onAfterSave() : Called right after a field is saved, and $this->model->id is set.
- onAfterElementSave() : Called right after an element is saved, and $this->element->id is set.
10. Which method is called right before a field is saved?
a) onBeforeSave()
b) BeforeSave()
c) SaveBefore()
d) onSave()
View Answer
Explanation: BaseFieldType provides three events that you can latch code onto:onBeforeSave(), onAfterSave() and onAfterElementSave(). The method onBeforeSave() is called right before a field is saved.
Sanfoundry Global Education & Learning Series – Javascript Programming.
- Check JavaScript Books
- Practice Information Science MCQs
- Practice MCA MCQs
- Check Programming Books
- Apply for Computer Science Internship