Merge branch 'feature/form_checkbox' into 'develop'
Feature/form checkbox See merge request BPHV_MIPS/mvm_core_ui!23
This commit is contained in:
commit
138f82bc8c
@ -324,7 +324,7 @@
|
||||
}
|
||||
|
||||
// key used to send text value to server
|
||||
string = [map string:@"fieldKey"];
|
||||
string = [map string:KeyFieldKey];
|
||||
if (string.length > 0) {
|
||||
self.fieldKey = string;
|
||||
}
|
||||
|
||||
@ -20,7 +20,8 @@
|
||||
|
||||
static const CGFloat FaultTolerance = 20.f;
|
||||
static const CGFloat CheckBoxHeightWidth = 18.0;
|
||||
@interface MVMCoreUICheckBox ()
|
||||
|
||||
@interface MVMCoreUICheckBox () <FormValidationProtocol, MVMCoreUIMoleculeViewProtocol>
|
||||
|
||||
@property (nonatomic, readwrite) BOOL isSelected;
|
||||
@property (weak, nonatomic) UIView *checkedSquare;
|
||||
@ -39,10 +40,45 @@ static const CGFloat CheckBoxHeightWidth = 18.0;
|
||||
@property (nullable, strong, nonatomic) NSLayoutConstraint *checkboxWidth;
|
||||
@property (nullable, strong, nonatomic) NSLayoutConstraint *checkboxHeight;
|
||||
|
||||
@property (nonatomic) BOOL isRequired;
|
||||
@property (nullable, strong, nonatomic) NSString *fieldKey;
|
||||
@property (nullable, strong, nonatomic) DelegateObject *delegate;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MVMCoreUICheckBox
|
||||
|
||||
#pragma mark - MVMCoreUIMoleculeViewProtocol
|
||||
|
||||
- (BOOL)needsToBeConstrained {
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (UIStackViewAlignment)moleculeAlignment {
|
||||
return UIStackViewAlignmentLeading;
|
||||
}
|
||||
|
||||
- (void)setWithJSON:(NSDictionary *)json delegateObject:(DelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData {
|
||||
|
||||
[FormValidator setupValidationWithMolecule:self delegate:((MVMCoreUIDelegateObject *)delegateObject).formValidationProtocol];
|
||||
self.delegate = delegateObject;
|
||||
self.fieldKey = [json stringForKey:KeyFieldKey];
|
||||
self.isRequired = [json boolForKey:KeyRequired];
|
||||
|
||||
NSString *checkedColorHex = [json string:@"checkedColor"];
|
||||
NSString *unCheckedColorHex = [json string:@"unCheckedColor"];
|
||||
|
||||
UIColor *checkedColor = checkedColorHex ? [UIColor mfGetColorForHex:checkedColorHex]: [UIColor blackColor];
|
||||
UIColor *unCheckedColor = unCheckedColorHex ? [UIColor mfGetColorForHex:unCheckedColorHex]: [UIColor clearColor];
|
||||
|
||||
[self setupWithCheckedColor:checkedColor
|
||||
unCheckColor:unCheckedColor
|
||||
label:[json dict:KeyLabel]
|
||||
delegateObject:delegateObject
|
||||
additionalData: additionalData];
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - convenient class methods
|
||||
|
||||
+ (instancetype)mfCheckBox {
|
||||
@ -69,8 +105,33 @@ static const CGFloat CheckBoxHeightWidth = 18.0;
|
||||
return checkBox;
|
||||
}
|
||||
|
||||
#pragma mark - FormValidationProtocol
|
||||
|
||||
- (BOOL)isValidField {
|
||||
if (self.isRequired) {
|
||||
return self.isSelected;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
- (nullable NSString *)formFieldName {
|
||||
return self.fieldKey;
|
||||
}
|
||||
|
||||
- (nullable id)formFieldValue {
|
||||
return @(self.isSelected);
|
||||
}
|
||||
|
||||
#pragma mark - inits
|
||||
|
||||
- (instancetype)init {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
[self setupView];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithCheckedColor:(UIColor *)checkedColor unCheckColor:(UIColor *)unCheckedColor text:(NSString *)text {
|
||||
if (self = [super init]) {
|
||||
[self setupWithCheckedColor:checkedColor unCheckColor:unCheckedColor text:text];
|
||||
@ -207,17 +268,25 @@ static const CGFloat CheckBoxHeightWidth = 18.0;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setupWithCheckedColor:(UIColor *)checkedColor unCheckColor:(UIColor *)unCheckedColor {
|
||||
if (checkedColor) {
|
||||
self.checkedColor = checkedColor;
|
||||
}
|
||||
if (unCheckedColor) {
|
||||
self.unCheckedColor = unCheckedColor;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setupWithCheckedColor:(UIColor *)checkedColor unCheckColor:(UIColor *)unCheckedColor text:(NSString *)text {
|
||||
[self setupView];
|
||||
if (checkedColor) {
|
||||
self.checkedColor = checkedColor;
|
||||
}
|
||||
if (unCheckedColor) {
|
||||
self.unCheckedColor = unCheckedColor;
|
||||
}
|
||||
[self setupWithCheckedColor:checkedColor unCheckColor:unCheckedColor];
|
||||
[self setDescriptionText:text];
|
||||
}
|
||||
|
||||
- (void)setupWithCheckedColor:(UIColor *)checkedColor unCheckColor:(UIColor *)unCheckedColor label:(NSDictionary *)labelJson delegateObject:(DelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData {
|
||||
[self setupWithCheckedColor:checkedColor unCheckColor:unCheckedColor];
|
||||
[self.descriptionLabel setWithJSON:labelJson delegateObject:delegateObject additionalData:additionalData];
|
||||
}
|
||||
|
||||
- (void)updateView:(CGFloat)size {
|
||||
[MVMCoreDispatchUtility performBlockOnMainThread:^{
|
||||
[self.descriptionLabel updateView:size];
|
||||
@ -254,7 +323,7 @@ static const CGFloat CheckBoxHeightWidth = 18.0;
|
||||
[self setSelected:selected animated:animated runBlock:YES];
|
||||
}
|
||||
|
||||
- (void)setSelected:(BOOL)selected animated:(BOOL)animated runBlock:(BOOL)runBlock{
|
||||
- (void)setSelected:(BOOL)selected animated:(BOOL)animated runBlock:(BOOL)runBlock {
|
||||
[self addAccessibilityLabel:selected];
|
||||
|
||||
self.isSelected = selected;
|
||||
@ -272,6 +341,9 @@ static const CGFloat CheckBoxHeightWidth = 18.0;
|
||||
} completion:nil];
|
||||
[self.checkMark updateCheckSelected:NO animated:animated];
|
||||
}
|
||||
|
||||
FormValidator *formValidator = ((MVMCoreUIDelegateObject *)self.delegate).formValidationProtocol.formValidatorModel;
|
||||
[formValidator enableByValidation];
|
||||
}
|
||||
|
||||
- (void)setColor:(nullable UIColor *)color forState:(UIControlState)state {
|
||||
|
||||
@ -44,13 +44,13 @@
|
||||
// Pins all edges to its super. 0 constant
|
||||
- (void)pinToSuperView;
|
||||
|
||||
// Add a view to be constrained in this view.
|
||||
- (void)addConstrainedView:(nonnull UIView *)view;
|
||||
|
||||
// Resets all the constraints to default.
|
||||
- (void)resetConstraints;
|
||||
|
||||
// For setting up the view.
|
||||
- (void)setupView;
|
||||
|
||||
// Add a view to be constrained in this view.
|
||||
- (void)addConstrainedView:(nonnull UIView *)view;
|
||||
|
||||
@end
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
view.backgroundColor = [UIColor clearColor];
|
||||
return view;
|
||||
}
|
||||
|
||||
|
||||
+ (nonnull ViewConstrainingView *)viewConstrainingView:(UIView *)view {
|
||||
ViewConstrainingView *constrainingView = [[ViewConstrainingView alloc] initWithFrame:CGRectZero];
|
||||
constrainingView.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
@ -52,7 +52,7 @@
|
||||
self.bottomPin = dictionary[ConstraintBot];
|
||||
self.rightPin = dictionary[ConstraintTrailing];
|
||||
}
|
||||
|
||||
|
||||
- (void)setPinConstantsWithInsets:(UIEdgeInsets)insets {
|
||||
[self setTopPinConstant:insets.top left:insets.left bottom:insets.bottom right:insets.right];
|
||||
}
|
||||
|
||||
@ -22,6 +22,6 @@ import Foundation
|
||||
// The Field name key value pair for sending to server
|
||||
@objc optional func formFieldName() -> String?
|
||||
|
||||
// The Feild value key value paid for sending to server
|
||||
@objc optional func formFieldValue() -> String?
|
||||
// The Field value key value pair for sending to server
|
||||
@objc optional func formFieldValue() -> Any?
|
||||
}
|
||||
|
||||
@ -32,7 +32,8 @@
|
||||
@"standardFooter": StandardFooterView.class,
|
||||
@"caretView": CaretView.class,
|
||||
@"caretButton": CaretButton.class,
|
||||
@"textField" : MFTextField.class
|
||||
@"textField" : MFTextField.class,
|
||||
@"checkbox" : MVMCoreUICheckBox.class
|
||||
} mutableCopy];
|
||||
});
|
||||
return mapping;
|
||||
|
||||
@ -38,6 +38,9 @@ extern NSString * const KeyTextColor;
|
||||
extern NSString * const KeyIsHidden;
|
||||
extern NSString * const KeyIsOpaque;
|
||||
|
||||
extern NSString * const KeyFieldKey;
|
||||
extern NSString * const KeyRequired;
|
||||
|
||||
#pragma mark - Values
|
||||
|
||||
extern NSString * const StringY;
|
||||
|
||||
@ -21,6 +21,8 @@ NSString * const KeyValue = @"value";
|
||||
NSString * const KeyLabel = @"label";
|
||||
NSString * const KeyDisable = @"disable";
|
||||
NSString * const KeyFieldName = @"fieldName";
|
||||
NSString * const KeyFieldKey = @"fieldKey";
|
||||
NSString * const KeyRequired = @"required";
|
||||
|
||||
NSString * const KeyHideMainMenu = @"hideMainMenu";
|
||||
NSString * const KeyProgressPercent = @"progressPercent";
|
||||
@ -37,6 +39,7 @@ NSString * const KeyTextColor = @"textColor";
|
||||
NSString * const KeyIsHidden = @"isHidden";
|
||||
NSString * const KeyIsOpaque = @"isOpaque";
|
||||
|
||||
|
||||
#pragma mark - Values
|
||||
|
||||
NSString * const StringY = @"Y";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user