Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to run instance.getRawValue(), please? #450

Open
jadamec opened this issue Mar 24, 2019 · 6 comments
Open

How to run instance.getRawValue(), please? #450

jadamec opened this issue Mar 24, 2019 · 6 comments

Comments

@jadamec
Copy link

jadamec commented Mar 24, 2019

How to do this via valHooks, please?
Basically each instance only applies to one input field, so you can run instance.getRawValue() to get raw value for specific input field.

Originally posted by @nosir in #138 (comment)

@xIDMONx
Copy link

xIDMONx commented Apr 3, 2019

How to do this via valHooks, please?
Basically each instance only applies to one input field, so you can run instance.getRawValue() to get raw value for specific input field.

Originally posted by @nosir in #138 (comment)

$('.superficie').toArray().forEach(function (field) {
            let cleave = new Cleave(field, {
                numeral:                    true,
                numeralPositiveOnly:        true,
                numeralThousandsGroupStyle: 'thousand'
            });
            
            $.valHooks[`#${$(field).attr('id')}`] = {
                get: function (el) {
                    return cleave.getRawValue();
                },
                set: function (el, val) {
                    $(el).html(val);
                }
            };
        });

$.valHooks["#txtSuperficieConstruida"].get()
"132654"

@jadamec
Copy link
Author

jadamec commented Apr 3, 2019

Thanks @xIDMONx , but it's still giving me an error A non well formed numeric value encountered after submitting the form so valHooks probably doesn't work.

$('.input-control-number').toArray().forEach(function (field) {
		var cleave = new Cleave(field, {
			numeral: true,
			numeralDecimalMark: ',',
			delimiter: ' '
		});

		$.valHooks[`#${$(field).attr('id')}`] = {
			get: function (el) {
				return cleave.getRawValue();
			},
			set: function (el, val) {
				$(el).html(val);
			}
		};
	});

	$('#m_post_edit_submit').on('click', function () {
		$.valHooks["#mortgage_value"].get();
		$.valHooks["#reality_value"].get();
	})

@jadamec
Copy link
Author

jadamec commented Apr 3, 2019

Fixed like below, but it's definitely like solution due to lack of time... I think problem is that Controller is taking input data directly and not like after the JS.

$request->merge([
			'mortgage_value' => str_replace(',', '.', str_replace(' ', '', $request->mortgage_value)),
			'reality_value' => str_replace(',', '.', str_replace(' ', '', $request->reality_value))
		]);

@jadamec
Copy link
Author

jadamec commented May 21, 2019

Anything new about this, please?

@ghost
Copy link

ghost commented Jul 4, 2021

Thanks @xIDMONx , but it's still giving me an error A non well formed numeric value encountered after submitting the form so valHooks probably doesn't work.

$('.input-control-number').toArray().forEach(function (field) {
		var cleave = new Cleave(field, {
			numeral: true,
			numeralDecimalMark: ',',
			delimiter: ' '
		});

		$.valHooks[`#${$(field).attr('id')}`] = {
			get: function (el) {
				return cleave.getRawValue();
			},
			set: function (el, val) {
				$(el).html(val);
			}
		};
	});

	$('#m_post_edit_submit').on('click', function () {
		$.valHooks["#mortgage_value"].get();
		$.valHooks["#reality_value"].get();
	})

how to set value?
get value from valHooks: let price_value = $.valhooks["#id_price"].get();
works fine.
set value to this input not working : $("#id_price").val(123456.23) , appears without formatting.
maybe set with valHooks, like this-$.valHooks["#id_price"].set("#id_price",123456.23)?
help me, please

@xIDMONx
Copy link

xIDMONx commented Jul 5, 2021

Hi @muzaman, try the following:

$.valHooks[`#${ $( field ).attr( 'id' ) }`] = {
    get: function ( el ) {
        return cleave.getRawValue();
    },
    set: function ( val ) {
        cleave.setRawValue( el );
    }
}

$.valHooks["#id_price"].set(123456);

I hope and it works for you

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

No branches or pull requests

2 participants