Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

275 řádky
6.8 KiB

  1. Form Widget API
  2. ===============
  3. Scripting Forms
  4. ----------------
  5. Custom scripts can be written in forms by writing events in "Client Script" / "Client Script Core" in the
  6. DocType. Some conventions for writing client scripts
  7. * All functions should be written in the namespace `cur_frm.cscript`. This namespace is set aside
  8. for customized client scripts
  9. * `cur_frm` is the global variable that represents the Current Form that is open.
  10. See Examples
  11. Form Container Class
  12. --------------------
  13. .. data:: _f
  14. Namespace for the Form Widget
  15. .. data:: _f.frm_con
  16. Global FrmContainer. There is only one instance of the Form Container
  17. .. function:: _f.get_value(dt, dn, fn)
  18. Returns the value of the field `fn` from DocType `dt` and name `dn`
  19. .. function:: _f.get_value(dt, dn, fn, v)
  20. Sets value `v` in the field `fn` of the give `dt` and `dn`
  21. * Will also set the record as __unsaved = 1
  22. * Will refresh the display so that the record is set as "Changes are not saved"
  23. .. class:: _f.FrmContainer
  24. This is the object that contains all Forms. The Form Container contains the page header and Form toolbar
  25. that is refreshed whenever a new record is shown.
  26. .. attribute:: head
  27. Element representing the header of the form.
  28. .. attribute:: body
  29. Element represnting the page body
  30. .. method:: show_head()
  31. Show the head element
  32. .. method:: hide_head()
  33. Show the head element
  34. .. method:: add_frm(doctype, onload, opt_name)
  35. Called internally by :func:`loaddoc`. Adds a new Form of type `doctype` in the FrmContainer.
  36. Form Class
  37. ----------
  38. .. class:: _f.Frm
  39. Each doctype has a Frm object. When records are loaded on the Frm object, fields inside the form are
  40. refreshed
  41. .. attribute:: doctype
  42. `doctype` of the current form
  43. .. attribute:: docname
  44. `name` of the current record
  45. .. attribute:: fields
  46. List of all `Field` objects in the form
  47. .. attribute:: fields_dict
  48. Dictionary of all `Field` objects in the form, identified by the `fieldname` or `label` (if no fieldname)
  49. exists
  50. .. attribute:: sections
  51. List of all sections known by section id (`sec_id`). (Id because Sections may not have headings / labels)
  52. .. attribute:: sections_by_label
  53. Dictionary of all sections by label. This can be used to switch to a particular section. Example::
  54. cur_frm.set_section(cur_frm.sections_by_label['More Details'].sec_id);
  55. .. method:: show()
  56. Show the form
  57. .. method:: hide()
  58. Hide the form
  59. .. method:: sec_section(sec_id)
  60. Show the section identified by
  61. .. method:: refresh()
  62. Refresh the current form. It will
  63. * Check permission
  64. * If the record is changed, load the new record data
  65. * Run 'refresh' method
  66. * Refresh all fields
  67. * Show the form
  68. .. method:: refresh_fields()
  69. Will refresh all fields
  70. .. method:: refresh_dependancy()
  71. Will refresh hide / show based on 'depends_on'
  72. .. method:: save(save_action, call_back)
  73. Will save the current record (function called from the "Save" button)
  74. save_action can be `Save`, `Submit`, `Cancel`
  75. .. method:: print_doc()
  76. Show the `Print` dialog
  77. .. method:: email_doc()
  78. Shows the `Email` dialog
  79. .. method:: copy_doc()
  80. Copy the current record
  81. .. method:: reload_doc()
  82. Reload the current record from the server
  83. .. method:: amend_doc()
  84. Amend the current Cancelled record
  85. .. method:: check_required(dt, dn)
  86. Checks whether all mandatory fields are filled
  87. .. method:: runscript(scriptname, callingfield, onrefresh)
  88. Run a server-side script where Trigger is set as `Server`. The server method is identified by
  89. `scriptname`
  90. .. method:: runclientscript(caller, cdt, cdn)
  91. Run a client script identified by the calling fieldname `caller`. `cdt` and `cdn` are the
  92. id of the calling `DocType and `name`
  93. .. method:: set_tip(txt)
  94. Clear existing tips and set a new tip (contextual help) in the Form
  95. .. method:: append_tip(txt)
  96. Add another tip to the existing tips
  97. .. method:: clear_tip()
  98. Clear all tips
  99. Field Class
  100. -----------
  101. .. class:: _f.Field()
  102. .. attribute:: df
  103. the `df` attribute represents the Field data. Standard Field properties are
  104. * fieldname
  105. * fieldtype
  106. * options
  107. * permlevel
  108. * description
  109. * reqd
  110. * hidden
  111. * search_index
  112. Example::
  113. var field = cur_frm.fields_dict['first_name']
  114. field.df.reqd = 1;
  115. field.refresh();
  116. .. attribute:: wrapper
  117. Wrapping DIV Element
  118. .. attribute:: label_area
  119. HTML Element where the label of the field is printed
  120. .. attribute:: disp_area
  121. HTML Element where the value of the field is printed in "Read" mode
  122. .. attribute:: input_area
  123. HTML Element where the widget is placed in "Write" mode
  124. .. attribute:: comment_area
  125. HTML Element where the comment (description) is printed
  126. .. attribute:: parent_section
  127. If the `section_style` of the doctype is `Tray` or `Tabbed`, then this represents the SectionBreak
  128. object in which this field is. This is used to switch to the section in case of an error.
  129. .. method:: get_status()
  130. Retuns the whether the field has permission to `Read`, `Write` or `None`
  131. .. method:: set(v)
  132. Sets a value to the field. Value is set in `locals` and the widget
  133. .. method:: run_trigger()
  134. Runs any client / server triggers. Called `onchange`
  135. Grid Class
  136. ----------
  137. .. class:: _f.FormGrid()
  138. The FromGrid Class inherits from the Grid class. The Grid class was designed to be a generic INPUT.
  139. * The metadata of the grid is defined by the `DocType` of the `Table` field.
  140. * Each column of the grid represents a field.
  141. * Each row of the grid represents a record
  142. **Grid Types**
  143. There are two type of Grids:
  144. #. Standard: Where fields can be edited within the cell
  145. #. Simple: Where fields are edited in a popup Dialog box. A Simple Grid can be created by setting the
  146. `default` property of the Table field to "Simple"
  147. When the user clicks on an editable Grid cell, it adds an `Field` object of that particular column to the
  148. cell so that the user can edit the values inside the cell. This `Field` object is known as the `template`
  149. The `template` can be accessed by the `get_field` method
  150. .. method:: get_field(fieldname)
  151. Returns the `template` (`Field` object) identified by `fieldname`
  152. .. method:: refresh()
  153. Refresh all data in the Grid
  154. Examples
  155. --------