Advertisement:

Author Topic: custom fields  (Read 93619 times)

spevoli

  • Jr. Member
  • **
  • Posts: 83
custom fields
« on: December 24, 2015, 12:00:45 am »
Hi,
where can I find in the item-post.php and in item.php the applied fields?
have two custom fields created that are created below this ...

 I would like to point at another place

thx, spevoli

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: custom fields
« Reply #1 on: December 24, 2015, 12:57:09 am »
Hi,

Where do you want to place your moved custom fields and what theme are you using?

Regards
« Last Edit: December 24, 2015, 01:06:06 am by teseo »

spevoli

  • Jr. Member
  • **
  • Posts: 83
Re: custom fields
« Reply #2 on: December 24, 2015, 04:18:47 pm »
Hi Teseo,

I use the infinity theme ...
am just change on and not get ahead ...

www.lokalanzeiger-mettmann.de
have created a test account
login: test pass: 12345678

Fields are above the submit button displayed ...

Thanks for the help

Spevoli

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: custom fields
« Reply #3 on: December 25, 2015, 06:32:36 pm »
Hi,

I've been perfecting my previous code to move custom fields on Ad posting / editing, and I think this is pretty advanced now:

Add this at the very bottom of your theme functions.php:
Notes:
1.- Take care not to leave blank lines after this.
2.- If your theme functions.php doesn't end with ?> skip first line of my code.

Code: [Select]
<?php
function custom_move_custom_field() {   
    
$section Rewrite::newInstance()->get_section();
    if (
$section == 'item_add' || $section == 'item_edit') { ?>


        <script type="text/javascript">
            $("#catId").ajaxComplete(function(){
               
                // Change these two values
                var customFieldIdentifier = 'art_der_anzeige';
                var destinationElement = $("label[for='select_1']").parent('div');

                var toMoveLabel = $("label[for='meta_" + customFieldIdentifier + "']");
                if (toMoveLabel.length && !$('#moved_custom_field').html()) {
                    $("<div></div>").attr('id', 'moved_custom_field').insertBefore(destinationElement);
                    $("<div></div>").attr('class', 'clear').css('padding-bottom', '10px').insertBefore(destinationElement);

                    toMoveLabel.parent('.meta').find('*').each(function( index, value ) {
                        $(this).copyCSS($(this));
                    });
                   
                    $("#moved_custom_field").append(toMoveLabel.parent('.meta'));
                } else {
                    $("#moved_custom_field").remove();
                }
            });
   
            $.fn.copyCSS = function (source) {
                var dom = $(source).get(0);
                var dest = {};
                var style, prop;
                if (window.getComputedStyle) {
                    var camelize = function (a, b) {
                        return b.toUpperCase();
                    };
                    if (style = window.getComputedStyle(dom, null)) {
                        var camel, val;
                        if (style.length) {
                            for (var i = 0, l = style.length; i < l; i++) {
                                prop = style[i];
                                camel = prop.replace(/\-([a-z])/, camelize);
                                val = style.getPropertyValue(prop);
                                dest[camel] = val;
                            }
                        } else {
                            for (prop in style) {
                                camel = prop.replace(/\-([a-z])/, camelize);
                                val = style.getPropertyValue(prop) || style[prop];
                                dest[camel] = val;
                            }
                        }
                        return this.css(dest);
                    }
                }
                if (style = dom.currentStyle) {
                    for (prop in style) {
                        dest[prop] = style[prop];
                    }
                    return this.css(dest);
                }
                if (style = dom.style) {
                    for (prop in style) {
                        if (typeof style[prop] != 'function') {
                            dest[prop] = style[prop];
                        }
                    }
                }
                return this.css(dest);
            };
        </script>

<?php }
}

osc_add_hook('footer''custom_move_custom_field'1);

function 
custom_remove_moved_custom_field() { ?>

    <script type="text/javascript">
        $("#moved_custom_field").remove();
    </script>
<?php }

osc_add_hook('item_form''custom_remove_moved_custom_field''6');
?>


Try it and tell me if everything's all right.

Regards

spevoli

  • Jr. Member
  • **
  • Posts: 83
Re: custom fields
« Reply #4 on: December 25, 2015, 07:07:31 pm »
Hello Teseo!,
have the rows are inserted, works perfectly
thank Teseo, you're my Santa Claus: D

if I want to insert other custom fields, do I need to insert an extra code and to take this opportunity to change something?

####################################
// Change these two values
                var customFieldIdentifier = 'art_der_anzeige';
                var destinationElement = $("label[for='select_1']").parent('div');
            
      var customFieldIdentifier = 'tuev_1';
                var destinationElement = $("label[for='select_2']").parent('div');
###################################

Best Regards
spevoli
« Last Edit: December 25, 2015, 07:15:41 pm by spevoli »

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: custom fields
« Reply #5 on: December 25, 2015, 07:28:02 pm »
You're welcome. :)

Adapting this code to work for two or more custom fields will need more work. I'll see what I can do during the weekend.

Regards


spevoli

  • Jr. Member
  • **
  • Posts: 83
Re: custom fields
« Reply #6 on: December 25, 2015, 07:35:27 pm »
I do not want that you're wasting your weekend for me :-)

I say thank you for the great help!  8)

 Spevoli

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: custom fields
« Reply #7 on: December 26, 2015, 06:07:08 pm »
***CORRECTED AGAIN***

Well, not exactly for you only, I'm always personally interested in finding better mechanisms to solve this problem of relocating Custom Fields.

This seems to work well with most of the existent themes out there (some of them would still require some adjustments  :o), but it should work for your Infinity:

(Replace the previous code)

Add this at the very bottom of your theme functions.php:
Notes:
1.- Take care not to leave blank lines after this.
2.- If your theme functions.php doesn't end with ?> skip first line of my code.

Code: [Select]
<?php
function custom_move_custom_field() {
    
$section Rewrite::newInstance()->get_section();
    if (
$section == 'item_add' || $section == 'item_edit') { ?>


    <script type="text/javascript">

        // Variable data, change values here only
        var customFieldsToMove = {
            0 : {   'cfIdentifier' : 'art_der_anzeige', 'destination': 'select_1'},
            1 : {   'cfIdentifier' : 'tuev_1', 'destination': 'select_2'}
        };
        // End Variable data

        $(document).ajaxComplete(function(event, xhr, settings){
           
            if (typeof settings['data'] == 'undefined' || settings['data'].indexOf('hook=item_') == -1) return; // No Category

            for(var i in customFieldsToMove) {
                customFieldIdentifier = customFieldsToMove[i]['cfIdentifier'];
                elementId = customFieldsToMove[i]['destination'];

                if ($("label[for='" + elementId + "']").length) {
                    var destinationElement = $("label[for='" + elementId + "']").parent('div');
                } else {
                    var destinationElement = $("select[id='" + elementId + "']").parent('div');
                }
                moveCustomField(customFieldIdentifier, destinationElement);
            }
        });

        function moveCustomField(customFieldIdentifier, destinationElement) {
            var movedId = 'moved_custom_field_' + customFieldIdentifier;
            var toMoveLabel = $("label[for='meta_" + customFieldIdentifier + "']");
           
            if (toMoveLabel.length && !$('#' + movedId).html()) {
                $("<div></div>").attr('id', movedId).insertBefore(destinationElement);

                if (destinationElement.prop('id').indexOf('meta_') == -1) {
                    toMoveLabel.parent('.meta').find('*').each(function() {
                        $(this).copyCSS($(this));
                    });
                }

                $('#' + movedId).append(toMoveLabel.parent('.meta'));
            } else {
                $('#' + movedId).remove();
            }
            $("<div></div>").attr('class', 'clear').css('padding-bottom', '10px').appendTo($('#' + movedId));
        }
       
        $.fn.copyCSS = function (source) {
            var dom = $(source).get(0);
            var dest = {};
            var style, prop;
            if (window.getComputedStyle) {
                var camelize = function (a, b) {
                    return b.toUpperCase();
                };
                if (style == window.getComputedStyle(dom, null)) {
                    var camel, val;
                    if (style.length) {
                        for (var i = 0, l = style.length; i < l; i++) {
                            prop = style[i];
                            camel = prop.replace(/\-([a-z])/, camelize);
                            val = style.getPropertyValue(prop);
                            dest[camel] = val;
                        }
                    } else {
                        for (prop in style) {
                            camel = prop.replace(/\-([a-z])/, camelize);
                            val = style.getPropertyValue(prop) || style[prop];
                            dest[camel] = val;
                        }
                    }
                    return this.css(dest);
                }
            }
            if (style = dom.currentStyle) {
                for (prop in style) {
                    dest[prop] = style[prop];
                }
                return this.css(dest);
            }
            if (style == dom.style) {
                for (prop in style) {
                    if (typeof style[prop] != 'function') {
                        dest[prop] = style[prop];
                    }
                }
            }
            return this.css(dest);
        };
    </script>

<?php }
}

osc_add_hook('footer''custom_move_custom_field'1);

function 
custom_remove_moved_custom_field() { ?>

    <script type="text/javascript">
        $("div [id^='moved_custom_field']").remove();
    </script>
<?php }

osc_add_hook('item_form''custom_remove_moved_custom_field'6);
?>


For other Osclass fellows interested in this procedure, you need to change this block:

Quote
        // Variable data, change values here only
        var customFieldsToMove = {
            0 : {   'cfIdentifier' : 'art_der_anzeige', 'destination': 'select_1'},
            1 : {   'cfIdentifier' : 'tuev_1', 'destination': 'select_2'}
        };
        // End Variable data

Well, I hope this will work for you, please let me know.

Regards
« Last Edit: May 10, 2016, 10:04:11 pm by teseo »

spevoli

  • Jr. Member
  • **
  • Posts: 83
Re: custom fields
« Reply #8 on: December 27, 2015, 01:35:44 pm »
Hello Teseo!
I will tonight installing your code and test everything;-)

thanks for the great support!
sign up as soon as I installed it ...

with best regards, spevoli

spevoli

  • Jr. Member
  • **
  • Posts: 83
Re: custom fields
« Reply #9 on: December 27, 2015, 09:09:12 pm »
Hello Teseo!

art_der_anzeige = appears above ...
tuev_01= reappears below ...

osclass ... never ending story :D
I wish you a nice week

Spevoli

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: custom fields
« Reply #10 on: December 27, 2015, 10:18:21 pm »
Don't understand... ??? Is it not working for you? Is this what is failing?

Code: [Select]
tuev_01= reappears below ...
What do you mean? In which subcategories should appear that custom field?

Regards

spevoli

  • Jr. Member
  • **
  • Posts: 83
Re: custom fields
« Reply #11 on: December 27, 2015, 11:45:47 pm »
Sorry!
I use to translate Google!  :-\
tuev_01 appears to me at the bottom, above submit

spevoli

spevoli

  • Jr. Member
  • **
  • Posts: 83
Re: custom fields
« Reply #12 on: December 27, 2015, 11:46:34 pm »
Sorry!
I use to translate Google!  :-\
tuev_01 appears to me at the bottom, above submit

spevoli

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: custom fields
« Reply #13 on: December 27, 2015, 11:58:00 pm »
But I don't see in your site my last code, but the first one... ???

Replace the code with that on this post:

http://forums.osclass.org/3-5-x/custom-fields-31684/msg134722/#msg134722

Regards

spevoli

  • Jr. Member
  • **
  • Posts: 83
Re: custom fields
« Reply #14 on: December 28, 2015, 03:54:07 pm »

sigh, because I slept ...
have the code inserted in the test function.php:   :-\

now I have to tinker a bit css for the break

thank you teseo :-)