@madivad try this and see field under age and value of returned diag when you select a segment
import dialogs
import datetime
import ui
#================ copy dialogs.form_dialog: begin
import collections
import sys
PY3 = sys.version_info[0] >= 3
if PY3:
basestring = str
def my_form_dialog(title='', fields=None, sections=None, done_button_title='Done'):
if not sections and not fields:
raise ValueError('sections or fields are required')
if not sections:
sections = [('', fields)]
if not isinstance(title, basestring):
raise TypeError('title must be a string')
for section in sections:
if not isinstance(section, collections.Sequence):
raise TypeError('Sections must be sequences (title, fields)')
if len(section) < 2:
raise TypeError('Sections must have 2 or 3 items (title, fields[, footer]')
if not isinstance(section[0], basestring):
raise TypeError('Section titles must be strings')
if not isinstance(section[1], collections.Sequence):
raise TypeError('Expected a sequence of field dicts')
for field in section[1]:
if not isinstance(field, dict):
raise TypeError('fields must be dicts')
#========== modify 1: begin
c = dialogs._FormDialogController(title, sections, done_button_title=done_button_title)
for s in range(0,len(c.sections)):
for i in range(0,len(c.cells[s])): # loop on rows of section s
cell = c.cells[s][i]
if len(cell.content_view.subviews) > 0:
tf = cell.content_view.subviews[0] # ui.TextField of value in row
item = c.sections[s][1][i] # section s, 1=items, row i
if 'segments' in item:
segmented = ui.SegmentedControl()
segmented.name = cell.text_label.text
segmented.frame = tf.frame
segmented.x = c.view.width - segmented.width - 8
segmented.segments = item['segments']
cell.content_view.remove_subview(tf)
del c.values[tf.name]
del tf
cell.content_view.add_subview(segmented)
#========== modify 1: end
c.container_view.present('sheet')
c.container_view.wait_modal()
# Get rid of the view to avoid a retain cycle:
c.container_view = None
if c.was_canceled:
return None
#========== modify 2: begin
for s in range(0,len(c.sections)):
for i in range(0,len(c.cells[s])): # loop on rows of section s
cell = c.cells[s][i]
if len(cell.content_view.subviews) > 0:
tf = cell.content_view.subviews[0] # ui.TextField of value in row
if isinstance(tf, ui.SegmentedControl):
if tf.selected_index >= 0:
item = c.sections[s][1][i] # section s, 1=items, row i
c.values[tf.name] = item['segments'][tf.selected_index]
#========== modify 2: end
return c.values
#================ copy dialogs.form_dialog: end
form_list_of_sections = []
sectionA_dicts = []
sectionA_dicts.append(dict(type = 'text', title = 'First Name',
key = 'first', placeholder = 'John'))
sectionA_dicts.append(dict(type = 'text', title = 'Last Name',
key = 'last', placeholder = 'Doe'))
sectionA_dicts.append(dict(type = 'number', title = 'age',
key = 'age', placeholder='30'))
sectionA_dicts.append(dict(type = 'text', title = 'My segmented control',
key = 'segm', segments = ['yes','no']))
form_list_of_sections.append(('Section A', sectionA_dicts, 'Section A ends'))
sectionB_dicts = []
sectionB_dicts.append(dict(type = 'date', title = 'Date Of Birth',
key = 'DOB', value = datetime.date.today()))
sectionB_dicts.append(dict(type = 'url', title = 'Home Page',
key = 'homepage', placeholder = 'http://example.com'))
form_list_of_sections.append(('Section B', sectionB_dicts, 'Section B ends'))
sectionC_dicts = []
sectionC_dicts.append(dict(type = 'email', title = 'email',
key = 'email', placeholder = 'name@mailserver.com'))
sectionC_dicts.append(dict(type = 'switch', title = 'is_married',
key = 'is_married', value = True))
sectionC_dicts.append(dict(type = 'check', title = 'is_registered',
key = 'is_registered', value = False))
form_list_of_sections.append(('Section C', sectionC_dicts, 'Section C ends'))
diag = my_form_dialog(title = 'Form Dialog', sections=form_list_of_sections)
print(diag)