JavaScript Questions & Answers – Crafting the Public API

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

Answer: c
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

Answer: b
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

Answer: b
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).
advertisement
advertisement

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

Answer: d
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

Answer: b
Explanation: getinputhtml() accepts two arguments: $name and $value. The parameter $name is the name you should assign your HTML input name= attribute.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

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

Answer: a
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

Answer: c
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).
advertisement

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

Answer: b
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

Answer: c
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.
advertisement

10. Which method is called right before a field is saved?
a) onBeforeSave()
b) BeforeSave()
c) SaveBefore()
d) onSave()
View Answer

Answer: a
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.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.