Force sequence of methods to have their call set to default?

Asked

Viewed 103 times

3

I have a framework that is used basically in building forms and events HTML/jQuery with PHP, an example call:

$VIDB_input = new \vidbModel\inputElement(); 
$documentos_date_action = 'triggered';
$documentos_date_conv = \vidbModel\convertDates::exec_format_date($data[0]['documentos_date'], 'd/m/Y', 'Y-m-d');
$documentos_date = $VIDB_input->value($documentos_date_conv)->field('documentos_date')->mask('date_br_d_m_Y')->name('documentos_date')->type('text')->validator('date_br')->additional_classnames('documentos_date')->datepicker('')->comboAction(true, $documentos_date_action)->comboValue('S/M')->input(0);

This above call does the same thing as this (there are more events but do not fit to the example):

        $(document).on('focusin', '.input-field', function () {
            var $this = $(this);
            var mask = $this.data('input-mask');
            if (mask === 'undefined') {
                console.log('no-mask');
            } else {
                console.log('put-mask');
            }
        });
    

$(document).on('click', '.combo-action-trigger', function () {
    var $this = $(this);
    var $input = $this.closest('.input-group').find('.input-field');
    var previousValue = $input.val();
    var previousMask = $input.data('input-mask');
    if ($this.is(':checked')) {
        var comboValue = $this.val();
        $input.data('input-mask', 'undefined');
        $input.data('previous-value', previousValue);
        $input.data('previous-mask', previousMask);
        $input.val(comboValue).prop('readonly', true);
    } else {
        var previousValueI = $input.data('previous-value');
        var previousMaskI = $input.data('previous-mask');
        $input.data('input-mask', previousMaskI);
        $input.val(previousValueI).prop('readonly', false);
    }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>


<div class="input-group"><input type="text" name="documentos_date" data-input-mask="date_br_d_m_Y" data-input-field="documentos_date" data-input-validator="date_br" value="S/M"class="form-control input-field documentos_date " readonly="true" ><span class="input-group-addon">S/M<input type="checkbox" class="combo-action-trigger" value="S/M" checked="true" ></span></div>

The problem happens in the following situation(For this example, it occurs in all situations when there is need to repeat the call):

I installed an input as in the previous example, and then I needed to start another input, but this new input, for example, would not receive any comboAction (comboAction is the name given to actions within a .input-group, as in the example, change the value of a field to a default value when marking the checkbox, and return to the previous value when unchecking it checkbox), this way it automatically pulls the value set in the previous call, in case it would start a second input with the comboAction to set the value when marking the checkbox if I don’t define false in this new call.

The value default for the method comboAction is false, i would like that, somehow, when starting this second call, it did not recover the value saved in the instance, but the value default method, but this without killing the instance, as I may need to render dozens of inputs in a form and it is not feasible to re-install every time, and this should apply to all methods of the classes in question.

  • Is it possible to define (maybe in a constructor? ) that a class should call X methods and if they are not previously called this constructor call them as default?
  • If possible, how to do this ?
  • If it’s not possible, is there any other solution? Or should I redesign the classes that would depend on this solution to work correctly ?

NOTE: I already made one question similar, but the problem was with the order of the call, this problem has already been solved with the comment left, only this problem remained with value residue in the instance.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.