XLFormRowDescriptor.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. //
  2. // XLFormRowDescriptor.h
  3. // XLForm ( https://github.com/xmartlabs/XLForm )
  4. //
  5. // Copyright (c) 2015 Xmartlabs ( http://xmartlabs.com )
  6. //
  7. //
  8. // Permission is hereby granted, free of charge, to any person obtaining a copy
  9. // of this software and associated documentation files (the "Software"), to deal
  10. // in the Software without restriction, including without limitation the rights
  11. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. // copies of the Software, and to permit persons to whom the Software is
  13. // furnished to do so, subject to the following conditions:
  14. //
  15. // The above copyright notice and this permission notice shall be included in
  16. // all copies or substantial portions of the Software.
  17. //
  18. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. // THE SOFTWARE.
  25. #import <Foundation/Foundation.h>
  26. #import "XLFormBaseCell.h"
  27. #import "XLFormValidatorProtocol.h"
  28. #import "XLFormValidationStatus.h"
  29. extern CGFloat XLFormUnspecifiedCellHeight;
  30. @class XLFormViewController;
  31. @class XLFormSectionDescriptor;
  32. @protocol XLFormValidatorProtocol;
  33. @class XLFormAction;
  34. @class XLFormBaseCell;
  35. typedef NS_ENUM(NSUInteger, XLFormPresentationMode) {
  36. XLFormPresentationModeDefault = 0,
  37. XLFormPresentationModePush,
  38. XLFormPresentationModePresent
  39. };
  40. typedef void(^XLOnChangeBlock)(id __nullable oldValue,id __nullable newValue,XLFormRowDescriptor* __nonnull rowDescriptor);
  41. @interface XLFormRowDescriptor : NSObject
  42. @property (nullable) id cellClass;
  43. @property (readwrite, nullable) NSString * tag;
  44. @property (readonly, nonnull) NSString * rowType;
  45. @property (nullable) NSString * title;
  46. @property (nonatomic, nullable) id value;
  47. @property (nullable) Class valueTransformer;
  48. @property UITableViewCellStyle cellStyle;
  49. @property (nonatomic) CGFloat height;
  50. @property (copy, nullable) XLOnChangeBlock onChangeBlock;
  51. @property BOOL useValueFormatterDuringInput;
  52. @property (nullable) NSFormatter *valueFormatter;
  53. // returns the display text for the row descriptor, taking into account NSFormatters and default placeholder values
  54. - (nonnull NSString *) displayTextValue;
  55. // returns the editing text value for the row descriptor, taking into account NSFormatters.
  56. - (nonnull NSString *) editTextValue;
  57. @property (nonatomic, readonly, nonnull) NSMutableDictionary * cellConfig;
  58. @property (nonatomic, readonly, nonnull) NSMutableDictionary * cellConfigForSelector;
  59. @property (nonatomic, readonly, nonnull) NSMutableDictionary * cellConfigIfDisabled;
  60. @property (nonatomic, readonly, nonnull) NSMutableDictionary * cellConfigAtConfigure;
  61. @property (nonnull) id disabled;
  62. -(BOOL)isDisabled;
  63. @property (nonnull) id hidden;
  64. -(BOOL)isHidden;
  65. @property (getter=isRequired) BOOL required;
  66. @property (nonnull) XLFormAction * action;
  67. @property (weak, null_unspecified) XLFormSectionDescriptor * sectionDescriptor;
  68. +(nonnull instancetype)formRowDescriptorWithTag:(nullable NSString *)tag rowType:(nonnull NSString *)rowType;
  69. +(nonnull instancetype)formRowDescriptorWithTag:(nullable NSString *)tag rowType:(nonnull NSString *)rowType title:(nullable NSString *)title;
  70. -(nonnull instancetype)initWithTag:(nullable NSString *)tag rowType:(nonnull NSString *)rowType title:(nullable NSString *)title;
  71. -(nonnull XLFormBaseCell *)cellForFormController:(nonnull XLFormViewController *)formController;
  72. @property (nullable) NSString *requireMsg;
  73. -(void)addValidator:(nonnull id<XLFormValidatorProtocol>)validator;
  74. -(void)removeValidator:(nonnull id<XLFormValidatorProtocol>)validator;
  75. -(nullable XLFormValidationStatus *)doValidation;
  76. // ===========================
  77. // property used for Selectors
  78. // ===========================
  79. @property (nullable) NSString * noValueDisplayText;
  80. @property (nullable) NSString * selectorTitle;
  81. @property (nullable) NSArray * selectorOptions;
  82. @property (null_unspecified) id leftRightSelectorLeftOptionSelected;
  83. // =====================================
  84. // Deprecated
  85. // =====================================
  86. @property (null_unspecified) Class buttonViewController DEPRECATED_ATTRIBUTE DEPRECATED_MSG_ATTRIBUTE("Use action.viewControllerClass instead");
  87. @property XLFormPresentationMode buttonViewControllerPresentationMode DEPRECATED_ATTRIBUTE DEPRECATED_MSG_ATTRIBUTE("use action.viewControllerPresentationMode instead");
  88. @property (null_unspecified) Class selectorControllerClass DEPRECATED_ATTRIBUTE DEPRECATED_MSG_ATTRIBUTE("Use action.viewControllerClass instead");
  89. @end
  90. typedef NS_ENUM(NSUInteger, XLFormLeftRightSelectorOptionLeftValueChangePolicy)
  91. {
  92. XLFormLeftRightSelectorOptionLeftValueChangePolicyNullifyRightValue = 0,
  93. XLFormLeftRightSelectorOptionLeftValueChangePolicyChooseFirstOption,
  94. XLFormLeftRightSelectorOptionLeftValueChangePolicyChooseLastOption
  95. };
  96. // =====================================
  97. // helper object used for LEFTRIGHTSelector Descriptor
  98. // =====================================
  99. @interface XLFormLeftRightSelectorOption : NSObject
  100. @property (nonatomic, assign) XLFormLeftRightSelectorOptionLeftValueChangePolicy leftValueChangePolicy;
  101. @property (readonly, nonnull) id leftValue;
  102. @property (readonly, nonnull) NSArray * rightOptions;
  103. @property (readonly, null_unspecified) NSString * httpParameterKey;
  104. @property (nullable) Class rightSelectorControllerClass;
  105. @property (nullable) NSString * noValueDisplayText;
  106. @property (nullable) NSString * selectorTitle;
  107. +(nonnull XLFormLeftRightSelectorOption *)formLeftRightSelectorOptionWithLeftValue:(nonnull id)leftValue
  108. httpParameterKey:(null_unspecified NSString *)httpParameterKey
  109. rightOptions:(nonnull NSArray *)rightOptions;
  110. @end
  111. @protocol XLFormOptionObject
  112. @required
  113. -(nonnull NSString *)formDisplayText;
  114. -(nonnull id)formValue;
  115. @end
  116. @interface XLFormAction : NSObject
  117. @property (nullable, nonatomic, strong) Class viewControllerClass;
  118. @property (nullable, nonatomic, strong) NSString * viewControllerStoryboardId;
  119. @property (nullable, nonatomic, strong) NSString * viewControllerNibName;
  120. @property (nonatomic) XLFormPresentationMode viewControllerPresentationMode;
  121. @property (nullable, nonatomic, strong) void (^formBlock)(XLFormRowDescriptor * __nonnull sender);
  122. @property (nullable, nonatomic) SEL formSelector;
  123. @property (nullable, nonatomic, strong) NSString * formSegueIdenfifier DEPRECATED_ATTRIBUTE DEPRECATED_MSG_ATTRIBUTE("Use formSegueIdentifier instead");
  124. @property (nullable, nonatomic, strong) NSString * formSegueIdentifier;
  125. @property (nullable, nonatomic, strong) Class formSegueClass;
  126. @end