Skip to content
This repository has been archived by the owner on Mar 7, 2021. It is now read-only.

Segment get unselected when combined with Show target #585

Closed
AnthoPakPak opened this issue Apr 17, 2018 · 2 comments
Closed

Segment get unselected when combined with Show target #585

AnthoPakPak opened this issue Apr 17, 2018 · 2 comments

Comments

@AnthoPakPak
Copy link
Contributor

Hi,

I've just tried to use the library but I encounter a bug with segment. I've bind a Show target on a specific value of the segment, and a Hide one on others. Whenever I click on the value with the Show target, the value get instantly unselected (it looks like it deselect when the Show has completed). The target field is correctly shown, but the clicked segment value get deselected. If I click a second time on the same value (so no target has to be performed), the value stay correctly selected.

I've tried several workarounds to reselect the value but none of them worked, for example :

self.dataSource.fieldUpdatedBlock = ^(id cell, FORMField *field) {
        BOOL shouldUpdateCivilite = ([field.fieldID isEqualToString:@"civilite"]);
        
        if (shouldUpdateCivilite) {
            [weakSelf.dataSource fieldWithID:@"civilite"
                       includingHiddenFields:YES
                                  completion:^(FORMField *field, NSIndexPath *indexPath) {
                                      if (field) {
                                          [field selectFieldValueWithValueID:@"Mme"];
                                          [weakSelf.dataSource reloadFieldsAtIndexPaths:@[indexPath]];
                                      }
                                  }];
        }
};

Here is my json file :

{
   "groups":[
      {
         "id":"demandeur-group",
         "title":"Demandeur",
         "sections":[
            {
               "id":"demandeur-group-0",
               "fields":[


                  {
                     "id":"civilite",
                     "title":"Civilité",
                     "type":"segment",
                     "values":[
                        {
                           "id":"M",
                           "title":"M",
                           "default":true,
                           "targets":[
                              {
                                 "id":"last_name_jeune_fille",
                                 "type":"field",
                                 "action":"hide"
                              }
                           ]
                        },
                        {
                           "id":"Mme",
                           "title":"Mme",
                           "targets":[
                              {
                                 "id":"last_name_jeune_fille",
                                 "type":"field",
                                 "action":"show"
                              }
                           ]
                        },
                        {
                           "id":"Mlle",
                           "title":"Mlle",
                           "targets":[
                              {
                                 "id":"last_name_jeune_fille",
                                 "type":"field",
                                 "action":"hide"
                              }
                           ]
                        }
                     ],
                     "size":{
                        "width":100,
                        "height":1
                     }
                  },


                  {
                     "id":"last_name",
                     "title":"Nom",
                     "type":"name",
                     "info":"Comme sur la pièce d'identité",
                     "size":{
                        "width":50,
                        "height":1
                     },
                     "validations":{
                        "required":true,
                        "min_length":2
                     }
                  },


                  {
                     "id":"first_name",
                     "title":"Prénom",
                     "info":"Comme sur la pièce d'identité",
                     "type":"name",
                     "size":{
                        "width":50,
                        "height":1
                     },
                     "validations":{
                        "required":true,
                        "min_length":2
                     }
                  },


                  {
                     "id":"last_name_jeune_fille",
                     "title":"Nom de jeune fille",
                     "type":"name",
                     "info":"Comme sur la pièce d'identité",
                     "size":{
                        "width":50,
                        "height":1
                     },
                     "validations":{
                        "required":true,
                        "min_length":2
                     }
                  }


                 
               ]
            }
         ]
      }
   ]
}

If anyone has an idea to help, I would be really thankful :)

@AnthoPakPak
Copy link
Contributor Author

AnthoPakPak commented Apr 17, 2018

I've found that the issue had already been solved here PR, but changes had not been reported in Cocoapods version.

But I've made a fix to get expected behavior :

replace
NSInteger *selectedIndex = [self.segment selectedSegmentIndex];
with
NSInteger selectedIndex = [self.segment selectedSegmentIndex];

AND

replace
if (selectedIndex || selectedIndex == 0)
with
if (selectedIndex && selectedIndex != UISegmentedControlNoSegment)

@3lvis
Copy link
Owner

3lvis commented Apr 17, 2018

I see, time to publish a new version then :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants