将一些值添加到inputText

如何解决将一些值添加到inputText

我正在设计一个带有primefaces 3.5和Java 8的网页。

此xhtml页面上有一个对话框,当用户按下某个按钮时会打开该对话框。此对话框包含有关地理位置和自动填充的javascript。根据此功能填充的一些输入文本(例如地址行1等),而其他由用户填充的文本(例如地址行2等)。

我的问题是,当用户完成地理位置操作并尝试填充手动字段时,对话框会不断地向右和向左移动。就像对话框试图停留在原处一样。

我没有分享整个页面。有很多字段是手动填充的,因此为了避免混淆,我删除了它们,但我只留下了地址行2。我没有删除自动填充的字段。您可以在下面看到代码。

<p:dialog id="addressDialog"
            onShow="#{managedBeanForPlaceOrder.addressAdd}"
            widgetVar="addressDialogWidget" modal="true" header="Ship To Address"
            closable="false"
            rendered="#{managedBeanForPlaceOrder.customer.addressCreationGrant}"
            resizable="false"
            width="400"
            style="max-height:700px; overflow:auto">
            <p:messages id="addressMessages" autoUpdate="true"></p:messages>
            
            
<style type="text/css">
    ::-webkit-input-placeholder {
        text-transform: initial;
    }
    
    :-moz-placeholder { 
       text-transform: initial;
    }
    
    ::-moz-placeholder {  
       text-transform: initial;
    }
    
    :-ms-input-placeholder { 
       text-transform: initial;
    }
    
    .pac-item {
    white-space:normal !important;
    }
</style>
<script type="text/javascript">
  // This example displays an address form,using the autocomplete feature
  // of the Google Places API to help users fill in the information.

  // This example requires the Places library. Include the libraries=places
  // parameter when you first load the API. For example:
  // <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places">

  var placeSearch,autocomplete;
  var componentForm = {
    street_number: 'short_name',route: 'long_name',locality: 'long_name',administrative_area_level_1: 'short_name',administrative_area_level_2: 'short_name',country: 'long_name',postal_code: 'short_name',political: 'short_name'
  };

  function initAutocomplete() {
    // Create the autocomplete object,restricting the search to geographical
    // location types.
    autocomplete = new google.maps.places.Autocomplete(
        /** @type {!HTMLInputElement} */(document.getElementById('autocomplete')),{types: []});

    // When the user selects an address from the dropdown,populate the address
    // fields in the form.
    autocomplete.addListener('place_changed',fillInAddress);
    document.getElementById('autocomplete').value = document.getElementById("addressForm:cua1").value;
    
    $(document).on("change",".pac-target-input",function(event) {
    document.getElementById("addressForm:cua1").value = document.getElementById('autocomplete').value;
    });
    
  }
  
  function fillInAddress() {
    // Get the place details from the autocomplete object.
    var place = autocomplete.getPlace();
    document.getElementById("addressForm:cua1").value = "";
    document.getElementById("addressForm:cua2").value = "";
    for (var component in componentForm) {
        
      if(!component && !document.getElementById(component)){
          document.getElementById(component).value = '';
          document.getElementById(component).disabled = false;
      } 
     
    }
    // Get each component of the address from the place details
    // and fill the corresponding field on the form.
    for (var i = 0; i < place.address_components.length; i++) {
      for (var j = 0; j < place.address_components[i].types.length; j++) {
          var addressType = place.address_components[i].types[j];
          if (componentForm[addressType]) 
          {
            var val = place.address_components[i][componentForm[addressType]];
           
            if (addressType == "locality") 
            {
                document.getElementById("addressForm:town").value = val;
            }
            else if (addressType == "street_number" || addressType == "route" || addressType == "neighborhood") 
            {
                if (val.length != 0){
                    if(document.getElementById("addressForm:cua1").value.length != 0) {
                        document.getElementById("addressForm:cua1").value = document.getElementById("addressForm:cua1").value.trim() + " " + val;
                    }
                    else{
                        document.getElementById("addressForm:cua1").value = val;
                    }
                }
            }
            else if (addressType == "country") 
            {
                if(val.toUpperCase() === "CANADA")
                {
                    countryCode.selectValue("CA");
                    document.getElementById("cscdInput").value = "CA";
                }
                else if(val.toUpperCase() === "UNITED STATES")
                {
                    countryCode.selectValue("US");
                    document.getElementById("cscdInput").value = "US";
                }
             }
            else if (addressType == "postal_code") 
            {
                document.getElementById("addressForm:postal_code").value = val;
                document.getElementById("opponoInput").value = val;
            }
            else if (addressType == "administrative_area_level_1") 
            {
                stateProvince.selectValue(val);
                document.getElementById("stateInput").value = val;
            }
          }
        }
      }
      document.getElementById('autocomplete').value = document.getElementById("addressForm:cua1").value;
    }

  // Bias the autocomplete object to the user's geographical location,// as supplied by the browser's 'navigator.geolocation' object.
  function geolocate() {
    if (navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(function(position) {
        var geolocation = {
          lat: position.coords.latitude,lng: position.coords.longitude
        };
        var circle = new google.maps.Circle({
          center: geolocation,radius: position.coords.accuracy
        });
        autocomplete.setBounds(circle.getBounds());
      });
    }
  }
  
  function getAllCodes(){
      stateProvince.selectValue(document.getElementById("stateInput").value);
      document.getElementById("addressForm:postal_code").value = document.getElementById("opponoInput").value;
  }

</script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAOHX1eQCUKHqsNmzArqsSmagr5_uesIVE&amp;libraries=places&amp;callback=initAutocomplete"
>
</script>
            
            <div style="width: 350px;margin: 0 auto;">
                
                <div style="width: 235px; margin: 0 auto;">
                    
                    <div style="margin-top: 10px; display:none">
                        <p:inputText maxlength="29" style="text-transform:capitalize;" id="cua1"
                            value="#{managedBeanForPlaceOrder.addressBean.OPCUA1}"></p:inputText>
                        <p:watermark value="*Address Line 1" for="cua1"></p:watermark>
                    </div>


                    <div style="margin-top: 10px;">
                        <p:inputText maxlength="29" style="text-transform:capitalize;" id="cua2" disabled="false"
                            value="#{managedBeanForPlaceOrder.addressBean.OPCUA2}"></p:inputText>
                        <p:watermark value="Address Line 2" for="cua2"></p:watermark>
                    </div>

                    <div style="margin-top: 10px;">
                        <p:selectOneMenu id="cscd" widgetVar="countryCode"
                            value="#{managedBeanForPlaceOrder.addressBean.OPCSCD}">
                            <f:selectItem itemValue="" itemLabel="*Country" />
                            <f:selectItems value="#{managedBeanForPlaceOrder.countryCodes}"></f:selectItems>
                            <p:ajax
                                listener="#{managedBeanForPlaceOrder.countryChangedListener}" oncomplete="getAllCodes()"
                                update="ecarGroup ponoGroup" process="cscd"></p:ajax>
                        </p:selectOneMenu>

                    </div>

                    <div style="margin-top: 10px;">
                        <h:panelGroup id="ecarGroup" >
                            <p:selectOneMenu id="ecar" widgetVar="stateProvince"
                                value="#{managedBeanForPlaceOrder.addressBean.OPECAR}">
                                <f:selectItem itemValue=""
                                    itemLabel="*State/Province" />
                                <f:selectItems value="#{managedBeanForPlaceOrder.stateCodes}"></f:selectItems>
                            </p:selectOneMenu>
                            <script type="text/javascript">
                            $('#addressForm\\:ecar').on('click',function(e){
                                if($('#addressForm\\:cscd_label').text() == 'Country')
                                {
                                     $('#addressForm\\:ecar_panel').hide();
                                      $('#addressForm\\:addressMessages').html(
                                          
                                          "<div class=\"ui-messages-error ui-corner-all\">" +
                                           "<span class=\"ui-messages-error-icon\">" + 
                                          "</span><ul><li>" + 
                                          "<span class=\"ui-messages-error-summary\">" +
                                            "Please first select country.</span></li>" +
                                          "</ul></div>"
                                        
                                        );
                                }
                            });
                            
                            </script>
                        </h:panelGroup>
                    </div>
                </div>
            </div>
        </p:dialog>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-