How to close popup after submitting values in react native?

Multi tool use
Multi tool use











up vote
3
down vote

favorite












I'm using react-native-popup-dialog. There is a single button within popup (yes). I want to close the button at same time I want to submit values to server.Now after clicking on yes button values get submit to server. How do I write close function at same onPress method? following is my code



onPressYes = (workType) => {
AsyncStorage.getItem('userid').then((usid) =>{
this.setState({
'userid': usid
});
console.log(usid);
fetch(GLOBAL.USER_REQUEST,{
method:'POST',
headers:{
'Accept': 'application/json',
'Content-Type': 'application/json',

},
body: JSON.stringify({
workType,
usid
})
})
.then(response => response.json())
.then((responseData) => {
this.setState({
data:responseData
});
});
})
}

popUpDialog = (id, workType) => {
this.setState ({
workType: workType
});
this.popupDialog.show();

}
render(){
return(
<PopupDialog ref={popupDialog => {
this.popupDialog = popupDialog;
}}
dialogStyle={{ backgroundColor: "#FFFFFF", height: 180, width:300, borderWidth:1,padding:10}}
overlayBackgroundColor="#fff" onDismissed={() => {
}}>
<View style={styles.dialogContentView}>
<Text style={{fontSize:18, margingTop:10,color:"#000000"}}>Are you sure you want to submit?</Text>
<View style={{alignSelf:'center'}}>

<View style={styles.button_1}>
<Button title="Yes" color="#8470ff" onPress={() => this.onPressYes(workType)}/>
</View>
);









share|improve this question


























    up vote
    3
    down vote

    favorite












    I'm using react-native-popup-dialog. There is a single button within popup (yes). I want to close the button at same time I want to submit values to server.Now after clicking on yes button values get submit to server. How do I write close function at same onPress method? following is my code



    onPressYes = (workType) => {
    AsyncStorage.getItem('userid').then((usid) =>{
    this.setState({
    'userid': usid
    });
    console.log(usid);
    fetch(GLOBAL.USER_REQUEST,{
    method:'POST',
    headers:{
    'Accept': 'application/json',
    'Content-Type': 'application/json',

    },
    body: JSON.stringify({
    workType,
    usid
    })
    })
    .then(response => response.json())
    .then((responseData) => {
    this.setState({
    data:responseData
    });
    });
    })
    }

    popUpDialog = (id, workType) => {
    this.setState ({
    workType: workType
    });
    this.popupDialog.show();

    }
    render(){
    return(
    <PopupDialog ref={popupDialog => {
    this.popupDialog = popupDialog;
    }}
    dialogStyle={{ backgroundColor: "#FFFFFF", height: 180, width:300, borderWidth:1,padding:10}}
    overlayBackgroundColor="#fff" onDismissed={() => {
    }}>
    <View style={styles.dialogContentView}>
    <Text style={{fontSize:18, margingTop:10,color:"#000000"}}>Are you sure you want to submit?</Text>
    <View style={{alignSelf:'center'}}>

    <View style={styles.button_1}>
    <Button title="Yes" color="#8470ff" onPress={() => this.onPressYes(workType)}/>
    </View>
    );









    share|improve this question
























      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      I'm using react-native-popup-dialog. There is a single button within popup (yes). I want to close the button at same time I want to submit values to server.Now after clicking on yes button values get submit to server. How do I write close function at same onPress method? following is my code



      onPressYes = (workType) => {
      AsyncStorage.getItem('userid').then((usid) =>{
      this.setState({
      'userid': usid
      });
      console.log(usid);
      fetch(GLOBAL.USER_REQUEST,{
      method:'POST',
      headers:{
      'Accept': 'application/json',
      'Content-Type': 'application/json',

      },
      body: JSON.stringify({
      workType,
      usid
      })
      })
      .then(response => response.json())
      .then((responseData) => {
      this.setState({
      data:responseData
      });
      });
      })
      }

      popUpDialog = (id, workType) => {
      this.setState ({
      workType: workType
      });
      this.popupDialog.show();

      }
      render(){
      return(
      <PopupDialog ref={popupDialog => {
      this.popupDialog = popupDialog;
      }}
      dialogStyle={{ backgroundColor: "#FFFFFF", height: 180, width:300, borderWidth:1,padding:10}}
      overlayBackgroundColor="#fff" onDismissed={() => {
      }}>
      <View style={styles.dialogContentView}>
      <Text style={{fontSize:18, margingTop:10,color:"#000000"}}>Are you sure you want to submit?</Text>
      <View style={{alignSelf:'center'}}>

      <View style={styles.button_1}>
      <Button title="Yes" color="#8470ff" onPress={() => this.onPressYes(workType)}/>
      </View>
      );









      share|improve this question













      I'm using react-native-popup-dialog. There is a single button within popup (yes). I want to close the button at same time I want to submit values to server.Now after clicking on yes button values get submit to server. How do I write close function at same onPress method? following is my code



      onPressYes = (workType) => {
      AsyncStorage.getItem('userid').then((usid) =>{
      this.setState({
      'userid': usid
      });
      console.log(usid);
      fetch(GLOBAL.USER_REQUEST,{
      method:'POST',
      headers:{
      'Accept': 'application/json',
      'Content-Type': 'application/json',

      },
      body: JSON.stringify({
      workType,
      usid
      })
      })
      .then(response => response.json())
      .then((responseData) => {
      this.setState({
      data:responseData
      });
      });
      })
      }

      popUpDialog = (id, workType) => {
      this.setState ({
      workType: workType
      });
      this.popupDialog.show();

      }
      render(){
      return(
      <PopupDialog ref={popupDialog => {
      this.popupDialog = popupDialog;
      }}
      dialogStyle={{ backgroundColor: "#FFFFFF", height: 180, width:300, borderWidth:1,padding:10}}
      overlayBackgroundColor="#fff" onDismissed={() => {
      }}>
      <View style={styles.dialogContentView}>
      <Text style={{fontSize:18, margingTop:10,color:"#000000"}}>Are you sure you want to submit?</Text>
      <View style={{alignSelf:'center'}}>

      <View style={styles.button_1}>
      <Button title="Yes" color="#8470ff" onPress={() => this.onPressYes(workType)}/>
      </View>
      );






      javascript reactjs react-native popup jsx






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 7 at 6:08









      anu

      316322




      316322
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          According to your code, you can use this.popupDialog.dismiss() instance method to hide a dialog:



          onPressYes = (workType) => {
          this.popupDialog.dismiss(); // action to close a dialog

          AsyncStorage.getItem('userid').then((usid) =>{
          this.setState({
          'userid': usid
          });
          console.log(usid);
          fetch(GLOBAL.USER_REQUEST,{
          method:'POST',
          headers:{
          'Accept': 'application/json',
          'Content-Type': 'application/json',

          },
          body: JSON.stringify({
          workType,
          usid
          })
          })
          .then(response => response.json())
          .then((responseData) => {
          this.setState({
          data:responseData
          });
          });
          })
          }





          share|improve this answer





















          • Yes , this worked for me thank you :)
            – anu
            Nov 7 at 7:51


















          up vote
          0
          down vote













          Using visible props to control it.



          import Dialog, { DialogContent } from 'react-native-popup-dialog';
          import { Button } from 'react-native'

          <View style={styles.container}>
          <Button
          title="Show Dialog"
          onPress={() => {
          this.setState({ visible: true }); // here
          }}
          />
          <Dialog
          visible={this.state.visible} // here
          onTouchOutside={() => {
          this.setState({ visible: false });
          }}
          >
          <DialogContent>
          {...}
          </DialogContent>
          </Dialog>
          </View>


          Ref: https://github.com/jacklam718/react-native-popup-dialog






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53184347%2fhow-to-close-popup-after-submitting-values-in-react-native%23new-answer', 'question_page');
            }
            );

            Post as a guest
































            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            2
            down vote



            accepted










            According to your code, you can use this.popupDialog.dismiss() instance method to hide a dialog:



            onPressYes = (workType) => {
            this.popupDialog.dismiss(); // action to close a dialog

            AsyncStorage.getItem('userid').then((usid) =>{
            this.setState({
            'userid': usid
            });
            console.log(usid);
            fetch(GLOBAL.USER_REQUEST,{
            method:'POST',
            headers:{
            'Accept': 'application/json',
            'Content-Type': 'application/json',

            },
            body: JSON.stringify({
            workType,
            usid
            })
            })
            .then(response => response.json())
            .then((responseData) => {
            this.setState({
            data:responseData
            });
            });
            })
            }





            share|improve this answer





















            • Yes , this worked for me thank you :)
              – anu
              Nov 7 at 7:51















            up vote
            2
            down vote



            accepted










            According to your code, you can use this.popupDialog.dismiss() instance method to hide a dialog:



            onPressYes = (workType) => {
            this.popupDialog.dismiss(); // action to close a dialog

            AsyncStorage.getItem('userid').then((usid) =>{
            this.setState({
            'userid': usid
            });
            console.log(usid);
            fetch(GLOBAL.USER_REQUEST,{
            method:'POST',
            headers:{
            'Accept': 'application/json',
            'Content-Type': 'application/json',

            },
            body: JSON.stringify({
            workType,
            usid
            })
            })
            .then(response => response.json())
            .then((responseData) => {
            this.setState({
            data:responseData
            });
            });
            })
            }





            share|improve this answer





















            • Yes , this worked for me thank you :)
              – anu
              Nov 7 at 7:51













            up vote
            2
            down vote



            accepted







            up vote
            2
            down vote



            accepted






            According to your code, you can use this.popupDialog.dismiss() instance method to hide a dialog:



            onPressYes = (workType) => {
            this.popupDialog.dismiss(); // action to close a dialog

            AsyncStorage.getItem('userid').then((usid) =>{
            this.setState({
            'userid': usid
            });
            console.log(usid);
            fetch(GLOBAL.USER_REQUEST,{
            method:'POST',
            headers:{
            'Accept': 'application/json',
            'Content-Type': 'application/json',

            },
            body: JSON.stringify({
            workType,
            usid
            })
            })
            .then(response => response.json())
            .then((responseData) => {
            this.setState({
            data:responseData
            });
            });
            })
            }





            share|improve this answer












            According to your code, you can use this.popupDialog.dismiss() instance method to hide a dialog:



            onPressYes = (workType) => {
            this.popupDialog.dismiss(); // action to close a dialog

            AsyncStorage.getItem('userid').then((usid) =>{
            this.setState({
            'userid': usid
            });
            console.log(usid);
            fetch(GLOBAL.USER_REQUEST,{
            method:'POST',
            headers:{
            'Accept': 'application/json',
            'Content-Type': 'application/json',

            },
            body: JSON.stringify({
            workType,
            usid
            })
            })
            .then(response => response.json())
            .then((responseData) => {
            this.setState({
            data:responseData
            });
            });
            })
            }






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 7 at 7:44









            Georgiy T.

            32438




            32438












            • Yes , this worked for me thank you :)
              – anu
              Nov 7 at 7:51


















            • Yes , this worked for me thank you :)
              – anu
              Nov 7 at 7:51
















            Yes , this worked for me thank you :)
            – anu
            Nov 7 at 7:51




            Yes , this worked for me thank you :)
            – anu
            Nov 7 at 7:51












            up vote
            0
            down vote













            Using visible props to control it.



            import Dialog, { DialogContent } from 'react-native-popup-dialog';
            import { Button } from 'react-native'

            <View style={styles.container}>
            <Button
            title="Show Dialog"
            onPress={() => {
            this.setState({ visible: true }); // here
            }}
            />
            <Dialog
            visible={this.state.visible} // here
            onTouchOutside={() => {
            this.setState({ visible: false });
            }}
            >
            <DialogContent>
            {...}
            </DialogContent>
            </Dialog>
            </View>


            Ref: https://github.com/jacklam718/react-native-popup-dialog






            share|improve this answer

























              up vote
              0
              down vote













              Using visible props to control it.



              import Dialog, { DialogContent } from 'react-native-popup-dialog';
              import { Button } from 'react-native'

              <View style={styles.container}>
              <Button
              title="Show Dialog"
              onPress={() => {
              this.setState({ visible: true }); // here
              }}
              />
              <Dialog
              visible={this.state.visible} // here
              onTouchOutside={() => {
              this.setState({ visible: false });
              }}
              >
              <DialogContent>
              {...}
              </DialogContent>
              </Dialog>
              </View>


              Ref: https://github.com/jacklam718/react-native-popup-dialog






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                Using visible props to control it.



                import Dialog, { DialogContent } from 'react-native-popup-dialog';
                import { Button } from 'react-native'

                <View style={styles.container}>
                <Button
                title="Show Dialog"
                onPress={() => {
                this.setState({ visible: true }); // here
                }}
                />
                <Dialog
                visible={this.state.visible} // here
                onTouchOutside={() => {
                this.setState({ visible: false });
                }}
                >
                <DialogContent>
                {...}
                </DialogContent>
                </Dialog>
                </View>


                Ref: https://github.com/jacklam718/react-native-popup-dialog






                share|improve this answer












                Using visible props to control it.



                import Dialog, { DialogContent } from 'react-native-popup-dialog';
                import { Button } from 'react-native'

                <View style={styles.container}>
                <Button
                title="Show Dialog"
                onPress={() => {
                this.setState({ visible: true }); // here
                }}
                />
                <Dialog
                visible={this.state.visible} // here
                onTouchOutside={() => {
                this.setState({ visible: false });
                }}
                >
                <DialogContent>
                {...}
                </DialogContent>
                </Dialog>
                </View>


                Ref: https://github.com/jacklam718/react-native-popup-dialog







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 7 at 6:43









                anhtu

                6,56121435




                6,56121435






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53184347%2fhow-to-close-popup-after-submitting-values-in-react-native%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest




















































































                    YcqrLgX78 nvHd41hvPsqF97,aZuYZim6y45zcp8ojw3uERyGKhnEcO 6aa
                    9wn1yhbQtfbzVw9

                    Popular posts from this blog

                    横浜市

                    Rostock

                    Золотое оружие «За храбрость»