文本字段显示值但未捕获它

时间:2016-11-16 15:53:45

标签: javascript jquery angularjs entity-attribute-value

我正在开发需要使用某些功能进行更新的项目。一个是我需要更新EAV注册表单并选择选项,我有2个单选按钮和文本字段。当我单击其中一个单选按钮时,它会获取该值并将其放在输入文本框中。当我尝试保存注册时问题就开始了。此文本字段属性保存在数据库中,其中一个是“isRequired”。我无法保存表单,因为textfield要求在其中键入内容,但已经存在一个值。当我禁用“isRequired”时,它会保存表单,但数据库中没有保存值。当我在单选按钮值旁边键入任何符号时,必填字段消失,然后我可以将值保存在数据库中。这就是为什么我的问题是为什么领域无法抓住价值的原因。我会在这个问题中加入一些代码,因为我无法创建测试环境。只有服务器上的文件。希望有人可以回答或提供一些线索。我认为这个问题可能是由按键事件,angularjs,jquery或EAV模型引起的。

图片:https://postimg.org/image/j8mgjia1d/

创建字段:

backendComponents.directive('eavFormatted', function($compile)
{
    return {
        restrict: "E",
        scope: true,
        replace: true,
        transclude: true,
        template: '<div class="form-group field_eav field_eav_{{ config.ID }} field_eav_{{ config.handle }}"><label class="control-label">{{ config.name }}</label><div ng-transclude></div></div>',
        link: function(scope, element, attrs)
        {
            var config = JSON.parse(attrs.config);
            scope.config = config;
            delete attrs.config;
            element.removeAttr('ng-transclude');
        }
    }
});

backendComponents.directive('eavField', function($compile, $timeout) {
            return {
                restrict: "E",
                scope: true,
                replace: true,
                link: function(scope, element, attrs)

                if (html) {
                    var fieldName = 'eav_' + config.ID;
                    if (config.isRequired) {
                        html = html + '<div class="text-danger" ng-show="isSubmitted && eavform.' + fieldName + '.$error.required">Lūdzu aizpildiet šo lauku</div>';
                    }

                    html = '<div><ng-form name="eavform">' + html + element.html() + '</ng-form></div>';

                    var newElem = angular.element(html);

                    var attrElem = input ? newElem.find(input) : newElem;

                    attrElem.attr('ng-model', 'vals.eav.' + config.ID);
                    attrElem.addClass('form-control');
                    attrElem.attr('placeholder', config.description);
                    attrElem.attr('name', fieldName);

                    if (config.isRequired) {
                        attrElem.attr('ng-required', true);
                    }
                }
            }
        }

来自浏览器的inspect元素的字段:

<div class="form-group field_eav field_eav_2 field_eav_epasts" config="{&quot;ID&quot;:2,&quot;eavFieldGroupID&quot;:null,&quot;classID&quot;:2,&quot;stringIdentifier&quot;:null,&quot;name&quot;:&quot;E-pasts&quot;,&quot;description&quot;:&quot;E-PASTS *&quot;,&quot;type&quot;:3,&quot;dataType&quot;:1,&quot;position&quot;:1,&quot;handle&quot;:&quot;epasts&quot;,&quot;isMultiValue&quot;:null,&quot;isRequired&quot;:1,&quot;isDisplayed&quot;:null,&quot;isDisplayedInList&quot;:null,&quot;valuePrefix&quot;:null,&quot;valueSuffix&quot;:null,&quot;valueFieldID&quot;:null,&quot;fieldName&quot;:&quot;specField_2&quot;}">
    <label class="control-label ng-binding">E-pasts</label>
    <div ng-transclude="">
        <div class="ng-scope">
            <ng-form name="eavform" class="ng-pristine ng-invalid ng-invalid-required">
                <input type="text" ng-model="vals.eav.2" class="form-control ng-pristine ng-invalid ng-invalid-required" placeholder="E-PASTS *" name="eav_2" ng-required="true" required="required">
                <div class="text-danger ng-hide" ng-show="isSubmitted &amp;&amp; eavform.eav_2.$error.required">Lūdzu aizpildiet šo lauku</div>
            </ng-form>
        </div>
    </div>
</div>

<div ng-transclude="">
    <div class="ng-scope">
        <ng-form name="eavform" class="ng-pristine ng-invalid ng-invalid-required">
            <input type="text" ng-model="vals.eav.2" class="form-control ng-pristine ng-invalid ng-invalid-required" placeholder="E-PASTS *" name="eav_2" ng-required="true" required="required">
            <div class="text-danger ng-hide" ng-show="isSubmitted &amp;&amp; eavform.eav_2.$error.required">Lūdzu aizpildiet šo lauku</div>
        </ng-form>
    </div>
</div>

文件中的代码

    <eav-formatted config="[[ eavFieldsHandle.epasts.toJson() ]]">
        <eav-field></eav-field>
    </eav-formatted>

            <legend style="padding-top: 0px;">Izvēlieties piegādes veidu: </legend>
              <input type="radio" class="input" name="radio-1" id="radio-1" value="Option1">
              <span><b>Choose 1</span>
              <input type="radio" class="input" name="radio-1" id="radio-2" value="Option2">
            <span><b>Choose 2</span>

文件脚本

      $( function() {

    $('input[name="radio-1"]').on('change', function() {

        $('input[name="eav_2"]').val($(this).val());
    });
} );

0 个答案:

没有答案