DateTimePicker

public struct DateTimePicker
extension DateTimePicker: View
extension DateTimePicker: _ViewEmptyChecking

DateTimePicker provides a title and value label with Fiori styling and a DatePicker.

Usage

@State var customizedDate: Date = .init(timeIntervalSince1970: 0.0)
@State var isRequired = false
@State var showsErrorMessage = false
@State var customizedPickerVisible = false
let customizedDateFormatter: DateFormatter = {
    let formatter = DateFormatter()
    formatter.dateFormat = "MM/dd/yyyy HH:mm:ss"
    return formatter
}()
func mandatoryFieldIndicator() -> TextOrIcon {
    var indicator = AttributedString("*")
    indicator.font = .fiori(forTextStyle: .title3)
    indicator.foregroundColor = Color.preferredColor(.indigo7)
    return .text(indicator)
}
@State var customizedPickerVisible = false

DateTimePicker(title: "Customized Date Formatter, locale and calendar", mandatoryFieldIndicator: self.mandatoryFieldIndicator(), isRequired: self.isRequired, selectedDate: self.$customizedDate, dateFormatter: self.customizedDateFormatter, pickerVisible: self.$customizedPickerVisible)
   .environment(\.locale, Locale(identifier: "zh-Hans"))
   .environment(\.calendar, Calendar(identifier: .gregorian))
  • Undocumented

    Declaration

    Swift

    public init(@ViewBuilder title: () -> any View,
                @ViewBuilder valueLabel: () -> any View = { EmptyView() },
                controlState: ControlState = .normal,
                errorMessage: AttributedString? = nil,
                range: ClosedRange<Date>? = nil,
                selectedDate: Binding<Date?> = .constant(nil),
                dateFormatter: DateFormatter? = nil,
                pickerComponents: DatePicker.Components = [.date, .hourAndMinute],
                dateStyle: Date.FormatStyle.DateStyle = .abbreviated,
                timeStyle: Date.FormatStyle.TimeStyle = .shortened,
                noDateSelectedString: String? = nil,
                pickerVisible: Binding<Bool>,
                hidesSeparator: Bool = false,
                showsClearAction: Bool = false,
                @ViewBuilder clearAction: () -> any View = { FioriIcon.actions.sysCancel.foregroundColor(.gray) },
                componentIdentifier: String? = DateTimePicker.identifier)
  • Convenience initializer for DateTimePicker

    Declaration

    Swift

    init(@ViewBuilder title: () -> any View,
         @ViewBuilder valueLabel: () -> any View = { EmptyView() },
         controlState: ControlState = .normal,
         errorMessage: AttributedString? = nil,
         range: ClosedRange<Date>? = nil,
         selectedDate: Binding<Date?> = .constant(nil),
         dateFormatter: DateFormatter? = nil,
         pickerComponents: DatePicker.Components = [.date, .hourAndMinute],
         dateStyle: Date.FormatStyle.DateStyle = .abbreviated,
         timeStyle: Date.FormatStyle.TimeStyle = .shortened,
         noDateSelectedString: String? = nil,
         pickerVisible: Binding<Bool>,
         hidesSeparator: Bool = false)

    Parameters

    title

    The title view for the date time picker.

    valueLabel

    The value view for the date time picker.

    controlState

    The ControlState of the form view. The default is normal.

    errorMessage

    The error message of the form view.

    range

    The inclusive range of selectable dates.

    selectedDate

    The date value being displayed and selected.

    dateFormatter

    The DateFormatter to be used to display the selected Date. Default formatter will use customized dateStyle and timeStyle.

    pickerComponents

    The components shown in the date picker, default value shows date and time.

    dateStyle

    The custom style for displaying the date. The default value is .abbreviated, showing for example, “Oct 21, 2015”.

    timeStyle

    The custom style for displaying the time. The default value is .shortened, showing for example, “4:29 PM” or “16:29”.

    noDateSelectedString

    The text to be displayed when no date is selected. If this property is nil, the localized string “No date selected” will be used.

    pickerVisible

    This property indicates whether the picker is to be displayed.

    hidesSeparator

    This property indicates whether the separator is to be displayed. Default is false.

  • Convenience initializer for DateTimePicker

    Declaration

    Swift

    init(title: AttributedString,
         valueLabel: AttributedString? = nil,
         mandatoryFieldIndicator: TextOrIcon? = .text("*"),
         isRequired: Bool = false,
         controlState: ControlState = .normal,
         errorMessage: AttributedString? = nil,
         range: ClosedRange<Date>? = nil,
         selectedDate: Binding<Date?>,
         dateFormatter: DateFormatter? = nil,
         pickerComponents: DatePicker.Components = [.date, .hourAndMinute],
         dateStyle: Date.FormatStyle.DateStyle = .abbreviated,
         timeStyle: Date.FormatStyle.TimeStyle = .shortened,
         noDateSelectedString: String? = nil,
         pickerVisible: Binding<Bool>,
         hidesSeparator: Bool = false)

    Parameters

    title

    The title string for the date time picker.

    valueLabel

    The value string for the date time picker.

    mandatoryFieldIndicator

    The mandatory field indicator for the date time picker.

    isRequired

    This property indicates whether the mandatory field indicator is to be displayed.

    controlState

    The ControlState of the form view. The default is normal.

    errorMessage

    The error message of the form view.

    range

    The inclusive range of selectable dates.

    selectedDate

    The date value being displayed and selected.

    dateFormatter

    The DateFormatter to be used to display the selected Date. Default formatter will use customized dateStyle and timeStyle.

    pickerComponents

    The components shown in the date picker, default value shows date and time.

    dateStyle

    The custom style for displaying the date. The default value is .abbreviated, showing for example, “Oct 21, 2015”.

    timeStyle

    The custom style for displaying the time. The default value is .shortened, showing for example, “4:29 PM” or “16:29”.

    noDateSelectedString

    The text to be displayed when no date is selected. If this property is nil, the localized string “No date selected” will be used.

    pickerVisible

    This property indicates whether the picker is to be displayed.

    hidesSeparator

    This property indicates whether the separator is to be displayed. Default is false.

  • Undocumented

    Declaration

    Swift

    static let identifier: String
  • Undocumented

    Declaration

    Swift

    init(title: AttributedString,
         valueLabel: AttributedString? = nil,
         mandatoryFieldIndicator: TextOrIcon? = .text("*"),
         isRequired: Bool = false,
         controlState: ControlState = .normal,
         errorMessage: AttributedString? = nil,
         range: ClosedRange<Date>? = nil,
         selectedDate: Binding<Date?>,
         dateFormatter: DateFormatter? = nil,
         pickerComponents: DatePicker.Components = [.date, .hourAndMinute],
         dateStyle: Date.FormatStyle.DateStyle = .abbreviated,
         timeStyle: Date.FormatStyle.TimeStyle = .shortened,
         noDateSelectedString: String? = nil,
         pickerVisible: Binding<Bool>,
         hidesSeparator: Bool = false,
         showsClearAction: Bool = false,
         @ViewBuilder clearAction: () -> any View = { FioriIcon.actions.sysCancel.foregroundColor(.gray) })
  • Undocumented

    Declaration

    Swift

    init(_ configuration: DateTimePickerConfiguration)
  • Declaration

    Swift

    @MainActor
    public var body: some View { get }
  • Undocumented

    Declaration

    Swift

    public var isEmpty: Bool { get }